mirror of
https://github.com/hanzoai/money.git
synced 2026-09-30 22:56:51 +00:00
d898597db175d56ed9abfc060c394fa02bc51fb8
money
The one exact money type for Go: an Amount in a Currency, backed by
hanzoai/decimal (big.Int fixed-point).
The community money pattern — never floats, integer-exact, Add/Sub/Split/Allocate,
same-currency safety — without the precision ceiling. int64/uint64 money libraries cap
around 19 digits (~$9.20 at 18 decimals); this holds a fiat cent and an 18-decimal
on-chain balance exactly.
price, _ := money.Parse("6.60", money.USD)
cost := price.Mul(decimal.New(200, 0)).Mul(decimal.MustParse("0.000001")) // "0.00132", never 0
bal, _ := money.FromCents(100).Sub(cost) // "0.99868"
husd, _ := money.Parse("100003.01", money.HUSD) // 18-dec on-chain unit
husd.MinorString() // "100003010000000000000000"
parts, _ := money.FromCents(100).Split(3) // 34 + 33 + 33 = 100, nothing lost
Currencies carry their smallest-unit decimals (USD 2, USDC 6, HUSD/ETH 18). BSD-3-Clause.
Description
Exact money (Amount+Currency) for Go on big.Int decimal — fiat + 18-dec crypto, no ceiling
87 KiB
Languages
Go
100%