$ show Rhymond/go-money
This is a Go library implementing the Money pattern for representing monetary values in a currency's smallest unit (e.g., cents). It provides precise arithmetic operations (addition, subtraction, multiplication, rounding), allocation and splitting of amounts without floating-point rounding errors, and formatting to human-readable strings with currency symbols and separators. The library includes a comprehensive set of ISO 4217 currency definitions, supports JSON serialization/deserialization with customizable marshal/unmarshal functions, and integrates with database/sql via Scanner and Valuer interfaces for storing monetary values in relational databases. It has no external dependencies beyond the Go standard library, making it lightweight and easy to embed. The architecture is a simple library with clear separation of concerns: a calculator for arithmetic, a formatter for display, a currency registry, and the core Money struct that composes these components.
The LLM identified 3 files worth highlighting for reuse:
Provides integer arithmetic operations (add, subtract, multiply, divide, modulus, allocate, absolute, negative, round) on the Amount type (int64). Isolated from the Money struct, it can be reused for any integer-based monetary calculations. Demonstrates clean separation of concerns and a strategy pattern for swapping calculation implementations.
Formats an integer amount (in smallest unit) to a human-readable string using currency-specific template, decimal/thousand separators, and grapheme. Handles negative amounts, zero padding, and thousands grouping. Can be extracted and used independently for formatting any integer with custom formatting rules.
Implements database/sql Scanner and Valuer interfaces for Money and Currency, allowing seamless storage and retrieval of monetary values in SQL databases using a configurable separator. Demonstrates idiomatic Go database integration and can be reused in any project needing to persist monetary values.