Go implementation of Fowler's Money pattern for precise monetary operations using integer amounts.
GoMoney is a Go library that implements Martin Fowler's Money pattern for handling monetary values safely and accurately. It prevents floating-point rounding errors by representing amounts as integers in a currency's smallest unit (e.g., cents) and provides operations like arithmetic, comparisons, splitting, and allocation with currency validation.
Go developers building financial applications, e-commerce systems, or any software requiring precise monetary calculations, such as payment processors, accounting tools, or budgeting apps.
Developers choose GoMoney for its strict adherence to Fowler's Money pattern, ensuring correctness and safety in financial computations by avoiding floating-point errors and catching currency mismatches. It offers built-in ISO 4217 currency support, precise operations, and utilities like allocation and formatting without losing pennies.
Go implementation of Fowler's Money pattern
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Represents monetary amounts as integers in the smallest unit (e.g., cents), eliminating floating-point rounding errors, as shown in initialization examples like money.New(100, money.GBP) for precise arithmetic.
Validates currency matches in operations, returning errors for mismatches (e.g., in comparisons like twoPounds.Equals(twoEuros)), preventing accidental cross-currency calculations.
Implements splitting and allocation with round-robin distribution of leftover pennies, ensuring no loss in financial divisions, demonstrated in the Split() and Allocate() examples.
Includes built-in constants for all ISO 4217 currency codes (e.g., money.GBP, money.EUR), simplifying international monetary handling without manual code definitions.
Lacks built-in support for currency conversion or exchange rate management, requiring developers to implement this separately if dealing with multi-currency transactions.
Focuses on arithmetic, comparisons, and allocation but omits advanced financial functions like interest calculation, rounding rules beyond integer units, or tax handling, which may need external libraries.
Using integers for amounts can lead to overflow if not managed carefully, especially with large values or currencies with high subunit counts, though the README doesn't address mitigation strategies.