A Go package implementing correctly rounded decimal floating-point numbers optimized for financial systems.
Decimal is a Go package that implements correctly rounded decimal floating-point numbers, providing precise arithmetic operations for financial and transactional systems. It solves the problem of floating-point inaccuracies in monetary calculations by offering mathematically correct rounding and high performance without heap allocations. The package is designed to be immutable, panic-free, and compatible with standard Go libraries.
Go developers building financial applications, payment systems, accounting software, or any system requiring precise decimal arithmetic with high performance and concurrency safety.
Developers choose Decimal for its combination of correctness (banker's rounding), speed (no heap allocations), and safety (immutable, panic-free), making it a reliable alternative to other decimal packages like shopspring/decimal and cockroachdb/apd.
Correctly rounded decimals for Go
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Uses half-to-even (banker's) rounding to 19 digits for mathematically accurate results, essential for financial calculations where precision is critical.
Optimized to avoid heap allocations during arithmetic operations, preventing garbage collector impact and ensuring high-speed performance, as shown in benchmarks with up to 600% faster operations compared to alternatives.
Methods return errors instead of panicking for cases like overflow or division by zero, improving application stability and reliability in production systems.
Decimal values are constant after creation, enabling safe concurrent access across goroutines without data races, which is ideal for high-concurrency financial environments.
Implements interfaces for direct compatibility with BSON, JSON, XML, and SQL packages, simplifying database interactions and API serialization without extra boilerplate.
Limited to 19 digits of precision, whereas competitors like cockroachdb/apd offer arbitrary precision, which may not suit applications requiring extremely high precision beyond financial scales.
The immutable nature requires creating new instances for every operation, which can increase memory usage and allocation in scenarios where mutable, in-place updates would be more efficient.
Compared to more established packages like shopspring/decimal, it has a smaller community, fewer third-party integrations, and less extensive documentation or examples, which could slow down onboarding.