Documentation ¶
Overview ¶
Example ¶
package main import ( "fmt" "github.com/gruzovator/money" ) func main() { _1usd := money.Make(1, 0, "USD") fmt.Println(_1usd) _1usd = money.Make(100, 2, "USD") fmt.Println(_1usd) _10usd := money.FromFloat(10.001, "USD") fmt.Println(_10usd) _100usd, _ := money.FromString("100.00 USD") fmt.Println(_100usd) }
Output: 1.00 USD 1.00 USD 10.00 USD 100.00 USD
Index ¶
- func CurrencyScalesFromISO4217(xmlContentReader io.Reader) (map[string]int, error)
- func DefaultScale() int
- func ForEachCurrency(cb func(code string, scale int))
- func IsKnownCurrency(curecnyCode string) bool
- func ReplaceCurrenciesSystem(scaleByCode map[string]int, defaultScale int)
- func ScaleForCurrency(currencyCode string) int
- type Converter
- type Money
- type RatesTableConverter
- type Sum
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CurrencyScalesFromISO4217 ¶
CurrencyScalesFromISO4217 parses currencies codes and scales from ISO417 XML data.
See:
func DefaultScale ¶
func DefaultScale() int
DefaultScale is scale value used for unknown currencies.
func ForEachCurrency ¶
ForEachCurrency is for currencies data iteration.
func IsKnownCurrency ¶
IsKnownCurrency checks if currency presents in ISO4217 data.
func ReplaceCurrenciesSystem ¶
ReplaceCurrenciesSystem should be used to replace package currencies data.
func ScaleForCurrency ¶
ScaleForCurrency gives scale value for currency code. Default scale is used for unknown currency.
Types ¶
type Money ¶
Money is amount of money as integer number of minor units and currency code.
func FromString ¶
FromString parses Money from string that has two parts: float value and currency code.
type RatesTableConverter ¶
type Sum ¶
Sum aggregates money values by currency.
func (*Sum) Calculate ¶
Calcuelate calculates sum value in target currency.
Example ¶
package main import ( "fmt" "github.com/gruzovator/money" ) func main() { converter := money.RatesTableConverter{ "USD": 1, "RUB": 60, } var sum money.Sum sum.Add(money.FromFloat(100, "USD")) sum.Add(money.FromFloat(600, "RUB")) sumValue, _ := sum.Calculate("USD", converter) fmt.Println(sumValue) }
Output: 110.00 USD