amount

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2023 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultPrecision = 24

Variables

View Source
var One, _ = big.NewInt(0).SetString("1000000000000000000000000", 10)

Functions

func Cmp

func Cmp(a, b Amount) int

Types

type Amount

type Amount big.Int

Amount is a wrapper around big.Int that implements decimal numbers with max precision of 18 digits

func Add

func Add(a, b Amount) Amount

func Mul

func Mul(a, b Amount) Amount

func MustNewFromString

func MustNewFromString(v string) Amount

func NewFromBigInt

func NewFromBigInt(v *big.Int) Amount

func NewFromInt

func NewFromInt(v int64) Amount

func NewFromIntWithPrecision

func NewFromIntWithPrecision(v *big.Int, precision int) Amount

NewFromIntWithPrecision creates a new Amount from an integer with the specified precision For example, if v = 100000 and precision = 3 the result amount will be 100.000

func NewFromString

func NewFromString(s string) (Amount, error)

func Sub

func Sub(a, b Amount) Amount

func Sum

func Sum(amounts ...Amount) Amount

func (Amount) Float

func (a Amount) Float() float64

func (Amount) Int

func (a Amount) Int() *big.Int

func (Amount) IntWithPrecision

func (a Amount) IntWithPrecision(precision int) *big.Int

IntWithPrecision returns a big.Int representation of number with the specified precision For example, if v = 100.000 and precision = 3 the result amount will be 100000 if v = 100.000 and precision = 5 the result amount will be 10000000

func (Amount) MarshalJSON

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

func (*Amount) Scan

func (a *Amount) Scan(src interface{}) error

func (Amount) String

func (a Amount) String() string

func (*Amount) UnmarshalJSON

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

func (Amount) Value

func (a Amount) Value() (driver.Value, error)

Jump to

Keyboard shortcuts

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