big.js
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|
Big.js is a small yet powerful JavaScript library for arbitrary-precision decimal arithmetic. It offers a simple API and is faster and easier-to-use than Java's BigDecimal JavaScript versions. Boasting a size of just 6 KB when minified, it replicates the toExponential
, toFixed
, and toPrecision
methods of JavaScript numbers. This library is designed for those who require precise arithmetic operations and value storage in a decimal floating point format.
To use the Big.js library, it needs to be installed first. If you're using a browser, you can add Big.js to the global scope using a script tag. Alternatively, you can import it as an ES module. If you're using Node.js, the library can be installed using npm and required in your script.
For simple usage, create a Big number from a primitive number, string, or another Big number. Here is an example:
const Big = require('big.js');
let x = new Big(123.4567);
let y = Big('123456.7e-3'); // 'new' is optional
let z = new Big(x);
console.log(x.eq(y) && x.eq(z) && y.eq(z)); // true
The methods that return a Big number can be chained. Like so:
let result = x.div(y).plus(z).times(9).minus('1.234567801234567e+8').plus(976.54321).div('2598.11772');
Additionally, you can invoke toExponential
, toFixed
and toPrecision
methods on your Big number:
x = new Big(255.5);
console.log(x.toExponential(5)); // "2.55500e+2"
console.log(x.toFixed(5)); // "255.50000"
console.log(x.toPrecision(5)); // "255.50"
You can find the comprehensive documentation for Big.js on GitHub. This includes a detailed guide and a list of method descriptions and their usage, beneficial for developers of all levels to understand the intricacies of this library.