finds.dev← search

// the find

leekchan/accounting

★ 910 · Go · MIT · updated Jul 2022

money and currency formatting for golang

A Go library for formatting numbers as money values — currency symbols, thousand/decimal separators, locale presets for 181 currencies. Essentially a port of accounting.js. Useful when you need to display monetary values in a Go backend or CLI without pulling in a full money library.

Supports `big.Rat`, `big.Float`, and `shopspring/decimal` so you can avoid float64 precision issues in financial code. Type-specific methods (FormatMoneyInt, FormatMoneyBigRat, etc.) let you skip reflection overhead when you know your type. The format string system (`%s %v`, `%s (%v)`) handles negative and zero display without conditional logic at the call site. Ships with a `LocaleInfo` map covering 181 currencies so you don't have to hardcode separators for EUR, CHF, JPY, etc.

Abandoned since 2022 — the `15` suffix on files (`accounting15.go`) is a Go 1.5 compatibility relic that was never cleaned up and signals low maintenance investment. No arithmetic: this is display-only, so you still need `shopspring/decimal` or similar for actual money math, making this a narrow dependency. `UnformatNumber` is simplistic — it strips formatting by pattern-matching rather than parsing locale-aware input, so round-tripping non-USD formats is fragile. No support for `decimal.Decimal` directly in `FormatMoney` via reflection despite having a dedicated `FormatMoneyDecimal` method, which means `FormatMoney(myDecimal)` silently falls through to an unhandled type.

View on GitHub →

// want more like this?

We dig through GitHub every week and send a few repos picked for what you actually care about — each with an honest take like this one.

Get finds in your inbox → Search again →