Documentation
¶
Overview ¶
Package money (piece ⑩) represents exact amounts of money in a currency.
Amounts are stored as integer minor units (cents) plus an ISO 4217 code, so they are exact, sortable and summable per currency. Arithmetic, conversion and locale formatting use bojanz/currency (decimal, CLDR data).
Index ¶
- Variables
- type Money
- func (m Money) Add(o Money) (Money, error)
- func (m Money) Amount() currency.Amount
- func (m Money) Convert(to, rate string) (Money, error)
- func (m Money) Decimal() string
- func (m Money) Format(locale string) string
- func (m Money) IsZero() bool
- func (m Money) Scale(factor string) (Money, error)
- func (m Money) String() string
Constants ¶
This section is empty.
Variables ¶
var ErrInvalid = errors.New("money: invalid amount")
ErrInvalid is returned for unknown currencies or malformed amounts.
Functions ¶
This section is empty.
Types ¶
type Money ¶
Money is an exact amount in a currency. The zero value is "no amount".
func Parse ¶
Parse parses a decimal string such as "12.99" in the given currency. The value is rounded to the currency's minor units.
func (Money) Convert ¶
Convert converts m into currency `to` using rate (units of `to` per unit of m.Currency, as a decimal string). The result is rounded to the minor units of `to`.
func (Money) Format ¶
Format formats the amount for a locale such as "es" or "en-US" ("12,99 €" / "€12.99").