money

package
v0.1.15 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2025 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Add

func Add(d1 *inf.Dec, d2 *inf.Dec) *inf.Dec

Return d1 + d2.

Values of d1 and d2 are unchanged.

func Div

func Div(d1 *inf.Dec, d2 *inf.Dec, scale int) *inf.Dec

Return d1 / d2 with HalfEven rounding.

Values of d1 and d2 are unchanged.

func Mul

func Mul(d1 *inf.Dec, d2 *inf.Dec) *inf.Dec

Return d1 * d2.

Values of d1 and d2 are unchanged.

func Round

func Round(d *inf.Dec, scale int) *inf.Dec

Round d to scale using HalfEven rounding mode.

Value of d is unchanged.

func RoundUnit

func RoundUnit(d *inf.Dec, unit currency.Unit) *inf.Dec

Round d to currency scale using HalfEven rounding mode.

Value of d is unchanged.

func Scale

func Scale(s string) (int, error)

Return scale of currency.

func Sub

func Sub(d1 *inf.Dec, d2 *inf.Dec) *inf.Dec

Return d1 - d2.

Values of d1 and d2 are unchanged.

func Unit

func Unit(s string) (currency.Unit, error)

Get currency unit.

func UnitDec

func UnitDec(amt string, unit currency.Unit) *inf.Dec

Create new signed arbitrary-precision decimal with appropriate scale for the currency and HalfEven rounding.

func UnitFmt

func UnitFmt(amt string, currency string) string

Format amount to appropriate scale for the currency using HalfEven rounding mode.

func UnitScale

func UnitScale(u currency.Unit) int

Get scale of currency unit.

Types

type Amt

type Amt inf.Dec

Amt represents arbitrary-precision decimal.

Amt is a type alias of inf.Dec. Amt can be used with encoding/json and gorm.

Different from inf.Dec, Amt always create new value for all math op (Add/Sub/Div/Mul) instead of setting the result back to the value itself.

Amt always use HalfEven rounding mode.

func NewAmt

func NewAmt(s string) *Amt

func Zero

func Zero() *Amt

func (*Amt) Abs

func (a *Amt) Abs() *Amt

func (*Amt) Add

func (a *Amt) Add(b *Amt) *Amt

func (*Amt) Cmp

func (a *Amt) Cmp(b *Amt) int

func (*Amt) Div

func (a *Amt) Div(b *Amt, scale int) *Amt

func (Amt) MarshalJSON

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

Implements encoding/json Marshaler

func (*Amt) Mul

func (a *Amt) Mul(b *Amt) *Amt

func (*Amt) Round

func (a *Amt) Round(scale int) *Amt

func (*Amt) RoundCurrency

func (a *Amt) RoundCurrency(currency string) (*Amt, error)

func (*Amt) RoundUnit

func (a *Amt) RoundUnit(unit currency.Unit) *Amt

func (*Amt) Scan

func (et *Amt) Scan(value interface{}) error

Implements sql.Scanner in database/sql.

func (*Amt) SetString

func (a *Amt) SetString(s string) error

func (*Amt) Sign

func (a *Amt) Sign() int

func (*Amt) String

func (a *Amt) String() string

func (*Amt) Sub

func (a *Amt) Sub(b *Amt) *Amt

func (*Amt) TryRoundCurrency

func (a *Amt) TryRoundCurrency(currency string) *Amt

func (*Amt) UnmarshalJSON

func (t *Amt) UnmarshalJSON(b []byte) error

Implements encoding/json Unmarshaler.

func (Amt) Value

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

Implements driver.Valuer in database/sql.

Jump to

Keyboard shortcuts

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