Versions in this module Expand all Collapse all v1 v1.0.0 Aug 26, 2026 Changes in this version + const MaxAllocationParts + const MaxAmountDigits + const MaxCashStep + const MaxMoneyBagEntries + const MaxRateMagnitude + const MaxRateSourceBytes + const MaxRatioDigits + const MaxScale + const MaxTaxRate + var ErrAmountLimit = errors.New("money: amount limit exceeded") + var ErrContextMismatch = errors.New("money: context mismatch") + var ErrCurrencyMismatch = errors.New("money: currency mismatch") + var ErrInvalidAllocation = errors.New("money: invalid allocation") + var ErrInvalidContext = errors.New("money: invalid context") + var ErrInvalidMoney = errors.New("money: invalid value") + var ErrInvalidRate = errors.New("money: invalid rate") + var ErrMinorUnitsUnavailable = errors.New("money: currency has no minor-unit metadata") + var ErrMoneyBagLimit = errors.New("money: bag limit exceeded") + var ErrPrecisionLoss = errors.New("money: precision loss") + var ErrUnknownCurrency = errors.New("money: unknown currency") + type AllocationResult struct + func (result AllocationResult) Parts() []Money + func (result AllocationResult) Sum() (Money, error) + type Amount struct + func AmountFromDecimal(value decimal.Decimal) (Amount, error) + func ParseAmount(input string) (Amount, error) + func (amount Amount) Decimal() decimal.Decimal + func (amount Amount) Equal(other Amount) bool + func (amount Amount) IsZero() bool + func (amount Amount) Scale() int32 + func (amount Amount) Sign() int + func (amount Amount) String() string + type Context struct + func AutomaticContext() Context + func CashContext(scale uint8, step uint64) (Context, error) + func CustomContext(scale uint8) (Context, error) + func DefaultContext(code currency.Code) (Context, error) + func (context Context) CashStep() uint64 + func (context Context) IsZero() bool + func (context Context) Kind() ContextKind + func (context Context) Scale() uint8 + type ContextKind uint8 + const ContextAutomatic + const ContextCash + const ContextCustom + const ContextDefault + type ConversionResult struct + func Convert(ctx context.Context, source Money, rate ExchangeRate, target Context, ...) (ConversionResult, error) + func (result ConversionResult) Converted() Money + func (result ConversionResult) Rate() ExchangeRate + func (result ConversionResult) Rounding() RoundingResult + func (result ConversionResult) Source() Money + type DiscountRate struct + func ParseDiscountRate(input string) (DiscountRate, error) + func (rate DiscountRate) Rate() Rate + type DiscountResult struct + func ApplyDiscount(ctx context.Context, original Money, rate DiscountRate, ...) (DiscountResult, error) + func (result DiscountResult) Discount() Money + func (result DiscountResult) Final() Money + func (result DiscountResult) Original() Money + func (result DiscountResult) Rounding() RoundingResult + type ExchangeRate struct + func NewExchangeRate(base, quote currency.Code, rate Rate, observedAt time.Time, source string) (ExchangeRate, error) + func (rate ExchangeRate) Base() currency.Code + func (rate ExchangeRate) Exact() Rate + func (rate ExchangeRate) ObservedAt() time.Time + func (rate ExchangeRate) Quote() currency.Code + func (rate ExchangeRate) Source() string + type Money struct + func FromMinorUnits(units integer.Integer, code currency.Code, context Context) (Money, error) + func Parse(input string, code currency.Code, context Context) (Money, error) + func (money Money) Abs() (Money, error) + func (money Money) Add(other Money) (Money, error) + func (money Money) Allocate(ctx context.Context, ratios []integer.Integer) (AllocationResult, error) + func (money Money) Amount() Amount + func (money Money) Compare(other Money) (int, error) + func (money Money) Context() Context + func (money Money) Currency() currency.Code + func (money Money) Equal(other Money) (bool, error) + func (money Money) EqualSplit(ctx context.Context, count int) (AllocationResult, error) + func (money Money) IsZero() bool + func (money Money) MinorUnits() (integer.Integer, error) + func (money Money) Mul(ctx context.Context, rate Rate) (RationalMoney, error) + func (money Money) Neg() (Money, error) + func (money Money) Quo(ctx context.Context, rate Rate) (RationalMoney, error) + func (money Money) Ratio(ctx context.Context, other Money) (Ratio, error) + func (money Money) Sign() int + func (money Money) String() string + func (money Money) Sub(other Money) (Money, error) + func (money Money) Valid() bool + type MoneyBag struct + func NewMoneyBag(values ...Money) (MoneyBag, error) + func (bag MoneyBag) Add(value Money) (MoneyBag, error) + func (bag MoneyBag) Get(code currency.Code, context Context) (Money, bool) + func (bag MoneyBag) Values() []Money + type Rate struct + func ParseRate(input string) (Rate, error) + func ParseRateWithMaximum(input, maximum string) (Rate, error) + func (rate Rate) IsZero() bool + func (rate Rate) Rational() rational.Rational + func (rate Rate) String() string + func (rate Rate) Valid() bool + type Ratio struct + func (ratio Ratio) Rational() rational.Rational + func (ratio Ratio) String() string + type RationalMoney struct + func (money RationalMoney) Currency() currency.Code + func (money RationalMoney) Rational() rational.Rational + func (money RationalMoney) Round(target Context, mode gomath.RoundingMode) (Money, RoundingResult, error) + func (money RationalMoney) String() string + type RoundingResult struct + func (result RoundingResult) Conditions() gomath.Condition + func (result RoundingResult) Inexact() bool + type TaxRate struct + func ParseTaxRate(input string) (TaxRate, error) + func (rate TaxRate) Rate() Rate + type TaxResult struct + func AddTax(ctx context.Context, net Money, rate TaxRate, mode gomath.RoundingMode) (TaxResult, error) + func ExtractTax(ctx context.Context, gross Money, rate TaxRate, mode gomath.RoundingMode) (TaxResult, error) + func (result TaxResult) Gross() Money + func (result TaxResult) Net() Money + func (result TaxResult) Rounding() RoundingResult + func (result TaxResult) Tax() Money