Deterministic, zero-dependency currency formatting for Go.
When generating invoices or financial reports, "close enough" isn't good enough. Standard Go locale libraries often fallback to US-style formatting (72,437.50) depending on the environment. This package provides a hard-coded registry of locale rules to ensure your numbers are formatted correctly for a small selection of locales (the ones I care about).
- Deterministic output: No reliance on system locales or external data.
- Granular access: Exported functions for Thousands(), Decimal(), and Symbol() for custom UI/PDF layouts.
- Nordic optimized: Native support for the unique spacing and symbol requirements of Norway, Sweden, and Denmark.
- Non-breaking spacing: Uses \u00A0 for separators to prevent currency amounts from wrapping in PDF or HTML outputs.
import "github.com/yourusername/currency"
func main() {
total := 72437.50
// Output: "72 437,50 kr"
fmt.Println(currency.Format(total, currency.NO))
}Useful when you need to style the currency symbol differently from the amount in a PDF or web frontend:
loc := currency.NO
sep := currency.Thousands(loc) // "\u00A0"
dec := currency.Decimal(loc) // ","
sym := currency.Symbol(loc) // "kr"
pre := currency.Placement(loc) // false (Symbol comes after)| Identifier | Country | Grouping | Decimal | Symbol | Example |
|---|---|---|---|---|---|
| currency.NO | Norway | Space (\u00A0) | , | kr | 72 437,50 kr |
| currency.SE | Sweden | Space (\u00A0) | , | kr | 72 437,50 kr |
| currency.DK | Denmark | . | , | kr. | 72.437,50 kr. |
| currency.GB | UK | , | . | £ | £72,437.50 |
| currency.IE | Ireland | , | . | € | €72,437.50 |
In professional Norwegian accounting (Faktura), the law requires clear presentation. While x/text/message is powerful, its tendency to "fail gracefully" back to US-English formats makes it a liability in financial software. This package treats locale rules as static configuration, guaranteeing that a Norwegian user will never see a US-style comma where a space should be.
Other locales have been added because of personal needs, and more may be added as needed.
MIT