Arbitrary-precision fixed-point decimal numbers in Go for accurate financial calculations.
Shopspring Decimal is a Go library for arbitrary-precision fixed-point decimal numbers, designed to handle monetary values and other calculations without the precision loss inherent in floating-point types. It ensures correctness in financial applications where exact decimal representation is critical by providing immutable operations and safe zero-value behavior.
Go developers building financial applications, e-commerce systems, or any software requiring exact decimal arithmetic, such as accounting tools, payment processors, or billing systems.
Developers choose this library for its correctness-first approach, ease of use with an API similar to standard Go numeric types, and built-in support for database and JSON/XML serialization, avoiding the subtle bugs common with float64 or big.Rat.
Arbitrary-precision fixed-point decimal numbers in 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.
The zero-value is 0 and safe to use without initialization, preventing null pointer errors in Go structs, as highlighted in the features.
Provides addition, subtraction, and multiplication with no loss of precision, ensuring correctness for financial calculations like taxes and fees.
Behaves like standard Go numeric types, returning new decimals without modifying originals, reducing subtle bugs compared to big.Int, as explained in the FAQ.
Offers out-of-the-box serialization/deserialization for database/sql, JSON, and XML, simplifying integration in APIs and data storage.
Prioritizes correctness over speed, causing extra memory allocations and slower operations compared to mutable alternatives like cockroachdb/apd, as admitted in the README.
Can only represent numbers with up to 2^31 digits after the decimal point, which may not suffice for all arbitrary-precision needs, such as extreme scientific calculations.
Lacks built-in advanced rounding modes; users must implement custom logic for financial rounding rules, adding complexity for precise monetary handling.