amount

package
v0.0.0-...-446988d Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 28, 2023 License: Apache-2.0, Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package amount provides utilities for converting numbers to/from the format used internally to gravity.

gravity represents asset "amounts" as 64-bit integers, but to enable fractional units of an asset, orbitr, the client-libraries and other built on top of gravity use a convention, encoding amounts as a string of decimal digits with up to six digits of precision in the fractional portion. For example, an amount shown as "101.001" in orbitr would be represented in gravity as 101001000.

Index

Constants

View Source
const (
	One = 1000000
)

One is the value of one whole unit of currency. Lantah uses 6 fixed digits for fractional values, thus One is 1 million (10^6).

Variables

This section is empty.

Functions

func IntStringToAmount

func IntStringToAmount(v string) (string, error)

IntStringToAmount converts string integer value and converts it to stellar "amount". In other words, it divides the given string integer value by 10^6 and returns the string representation of that number. It is safe to use with values exceeding int64 limits.

func MustParse

func MustParse(v string) xdr.Int64

MustParse is the panicking version of Parse.

func Parse

func Parse(v string) (xdr.Int64, error)

Parse parses the provided as a stellar "amount", i.e. a 64-bit signed integer that represents a decimal number with 6 digits of significance in the fractional portion of the number, and returns a xdr.Int64.

func ParseInt64

func ParseInt64(v string) (int64, error)

ParseInt64 parses the provided as a stellar "amount", i.e. a 64-bit signed integer that represents a decimal number with 6 digits of significance in the fractional portion of the number.

func String

func String(v xdr.Int64) string

String returns an "amount string" from the provided raw xdr.Int64 value `v`.

func String128

func String128(v xdr.Int128Parts) string

String128 converts a signed 128-bit integer into a string, boldly assuming 6-decimal precision.

TODO: This should be adapted to variable precision when appopriate, but 6 decimals is the correct default for Lantah Classic amounts.

func StringFromInt64

func StringFromInt64(v int64) string

StringFromInt64 returns an "amount string" from the provided raw int64 value `v`.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL