mirror of
https://github.com/hanzoai/decimal.git
synced 2026-09-30 21:40:38 +00:00
44ccd24fc0367ac906d0725e97e22d8ede773694
Superseded: the Hanzo GitHub App pushes a webhook, so the forge tracks GitHub without a per-repo workflow. This file called git.hanzo.ai/api/v1/.../mirror-sync — a Gitea API for a system we no longer drive — and would sit inert in every repo. One mechanism, in one place, instead of ~350 copies of a cron.
decimal
Exact, arbitrary-precision fixed-point decimal for Go. A value is coefficient × 10⁻ˢᶜᵃˡᵉ
with a big.Int coefficient — no precision ceiling, no float, immutable.
Unlike int64/uint64 decimal & money libraries (which cap around 19 digits — about $9.20
at 18 decimals), this holds a fiat cent and an 18-decimal on-chain wei balance with equal
exactness. 0.1 + 0.2 is exactly 0.3.
d := decimal.MustParse("6.60")
cost := decimal.New(200, 0).Mul(d).Quo(decimal.New(1_000_000, 0), 18) // 200 tokens @ $6.60/1M
cost.String() // "0.00132" (never floored to 0)
The numeric core beneath hanzoai/money. Stdlib only.
BSD-3-Clause.
Languages
Go
100%