bignumber.js is a JavaScript library for arbitrary-precision decimal and non-decimal arithmetic.
The library solves the problem of precision loss when performing calculations with numbers in JavaScript, where the native Number type has inherent limitations. It provides a BigNumber constructor that accepts values as numbers, strings, BigInts, or other BigNumber instances, allowing developers to work with integers and decimals of arbitrary precision. The library replicates familiar methods from JavaScript's Number type such as toExponential, toFixed, and toPrecision, while adding specialized methods like toFraction and a correctly-rounded squareRoot function. It supports multiple number bases from 2 to 36 and includes cryptographically-secure pseudo-random number generation.
Developers should choose this library when precision is critical and native JavaScript numbers are insufficient. It suits financial calculations, scientific computing, and any application requiring exact decimal arithmetic. The library is compact at 8 KB minified and gzipped with no external dependencies, making it suitable for browser and Node.js environments. The README identifies two related alternatives: big.js, which is smaller and simpler but handles only decimal numbers with fewer methods and configuration options, and decimal.js, which adds support for non-integer powers and performs operations to a specified number of significant digits.
The project maintains responsive engagement with its community, with maintainers typically responding to new issues and pull requests within a few days.