Decimal.js is an arbitrary-precision decimal type for JavaScript that handles numbers with exact arithmetic beyond the limits of native floating-point.
The problem it solves is the loss of precision inherent in JavaScript's standard Number type, which uses binary floating-point representation and cannot accurately represent many decimal values. Decimal.js provides exact arithmetic by storing values as digits, exponent, and sign, then rounding all calculations to a configurable precision measured in significant digits rather than decimal places. This approach mirrors Python's decimal module and ensures consistent rounding behavior across all operations, not just division.
Developers should choose this tool when working with financial calculations, scientific computations, or any domain where decimal precision matters. It suits projects that need to handle hexadecimal, binary, and octal values alongside decimals, and those requiring trigonometric functions and non-integer powers. The README distinguishes it from bignumber.js by noting that precision is specified in significant digits with rounding applied to all calculations, and from big.js by including trigonometric functions and support for non-integer powers. A lighter variant without trigonometric functions is available for projects that do not need those capabilities.
The project maintains comprehensive documentation and an extensive test suite. The library has no external dependencies and achieves broad platform compatibility by using only JavaScript 1.5 features. It includes a TypeScript declaration file for type-safe usage. The codebase is distributed as both a single JavaScript file and an ES module, with method names offering shorter aliases for common operations and most methods of JavaScript's Number.prototype and Math objects replicated for familiarity.