Documentation ¶
Overview ¶
Package money represents money values with no loss in precision and without rounding errors.
Index ¶
- Variables
- type FormatConfig
- type Money
- func (m Money) Add(other Money) Money
- func (m Money) AddTaxPercent(tax int32) Money
- func (m Money) Cents() int32
- func (m Money) Div(other Money) Money
- func (m Money) Format(config FormatConfig) string
- func (m Money) IsZero() bool
- func (m Money) LessThan(other Money) bool
- func (m Money) Mul(n int32) Money
- func (m Money) String() string
- func (m Money) Sub(other Money) Money
Constants ¶
This section is empty.
Variables ¶
View Source
var ( EUR = FormatConfig{ Symbol: "\u20ac", Thousand: ",", } USD = FormatConfig{ Symbol: "$", Prefix: true, Thousand: ",", } GBP = FormatConfig{ Symbol: "\u00a3", Prefix: true, Thousand: ",", } MXN = FormatConfig{ Symbol: "Mex$", Prefix: true, Thousand: ",", } )
Functions ¶
This section is empty.
Types ¶
type FormatConfig ¶ added in v1.55.0
type FormatConfig struct { Symbol string Prefix bool Thousand string Decimal string ForceDecimals bool }
func Currency ¶ added in v1.55.0
func Currency(currency string) FormatConfig
Currency returns the configuration of a currency by its name. Unknown currencies will return the default config.
type Money ¶
type Money int32
func Parse ¶
Parse a string to create a new money value. It can read `XX.YY` and `XX,YY`. An empty string is parsed as zero.
func (Money) AddTaxPercent ¶
AddTaxPercent adds a percentage of the price to itself.
func (Money) Format ¶
func (m Money) Format(config FormatConfig) string
Format the money value with a specific configuration.
Click to show internal directories.
Click to hide internal directories.