amount

package
v1.2.5 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2020 License: MIT Imports: 4 Imported by: 4

Documentation

Index

Constants

View Source
const Precision = 18

Precision of amount

Variables

This section is empty.

Functions

This section is empty.

Types

type Amount

type Amount struct {
	Value *big.Int
}

Amount is amount of token in Sumus

func FromAmount

func FromAmount(a *Amount) *Amount

FromAmount creates an instance and copies a value from another instance

func FromBig

func FromBig(b *big.Int) *Amount

FromBig creates an instance, setting it's value from big integer (100 => 0.000000000000000100)

func FromBigString

func FromBigString(s string, base int) (*Amount, error)

FromBigString creates an instance from a string containing big integer representation of the value. Example: "0100" (base 10) => 0.000000000000000100, "100" (base 00) => 0.000000000000000100 Example: "000A" (base 16) => 0.000000000000000010, "0xA" (base 00) => 0.000000000000000010 Example: "0144" (base 08) => 0.000000000000000100, "012" (base 00) => 0.000000000000000010

func FromInteger

func FromInteger(i int64) *Amount

FromInteger creates an instance, setting integral part of it's value from integer (100 => 100.000000000000000000)

func FromString

func FromString(s string) (*Amount, error)

FromString creates an instance from a string containing float-point representation of the value. Example: "1.000000000000000000123" => 1.000000000000000000 Example: "1.000000000000000000999" => 1.000000000000000001

func MustFromBigString

func MustFromBigString(s string, base int) *Amount

MustFromBigString does the same as FromBigString, but panics on error

func MustFromString

func MustFromString(s string) *Amount

MustFromString does the same as FromString, but panics on error

func New

func New() *Amount

New amount instance

func (*Amount) Float64

func (a *Amount) Float64() float64

Float64 approximation (6 decimal places)

func (*Amount) Fraction

func (a *Amount) Fraction(width uint) string

Fraction part as string: -123.000000000000456000 => "456000" (width 0) -123.000000000000456000 => "000000000000456000" (width 18)

func (*Amount) Integer

func (a *Amount) Integer(width uint) string

Integer part as string: -123.000000000000456000 => "123" (width 0) -123.000000000000456000 => "00123" (width 5)

func (*Amount) IsNeg

func (a *Amount) IsNeg() bool

IsNeg value

func (*Amount) MarshalJSON

func (a *Amount) MarshalJSON() ([]byte, error)

MarshalJSON impl.

func (*Amount) String

func (a *Amount) String() string

String representation: -100.000000000000000123

func (*Amount) UnmarshalJSON

func (a *Amount) UnmarshalJSON(b []byte) error

UnmarshalJSON impl.

Jump to

Keyboard shortcuts

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