bignumber.js
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|
bignumber.js is an efficient JavaScript library designed to execute arbitrary-precision decimal and non-decimal arithmetic operations. With a simple and robust API, it enables faster, smaller and more straightforward arithmetic calculations compared to the Java's BigDecimal JavaScript versions. This library comes with a variety of features, including the replication of JavaScript's toExponential
, toFixed
, toPrecision
, and toString
methods, and a new toFraction
and a correctly-rounded squareRoot
method. It is designed to offer wide platform compatibility, utilizing JavaScript 1.5 (ECMAScript 3) features, and it does not depend on any other libraries.
The bignumber.js library is easy to use and you can start by installing it in Node.js using the command npm install bignumber.js
. Once installed, you can require or import the library into your code file:
const BigNumber = require('bignumber.js');
// or
import BigNumber from "bignumber.js";
You can now perform operations using the BigNumber constructor function. For example:
let x = new BigNumber(123.4567);
let y = BigNumber('123456.7e-3');
To get a BigNumber value as a string, you can use toString()
or toFixed()
methods:
let x = new BigNumber('1111222233334444555566');
console.log(x.toString()); // "1.111222233334444555566e+21"
console.log(x.toFixed()); // "1111222233334444555566"
The API also supports chaining to execute multiple operations in one go:
x.dividedBy(y).plus(z).times(9)
The bignumber.js library provides comprehensive and detailed documentation, which can be found here. The documentation offers a useful guide to users on how to use and optimize the functionality of the library effectively. It includes detailed sections on BigNumber.js's methods, properties, configuration, and even performance notes. Furthermore, the documentation site provides examples, API reference, and information about certain intricate details for advanced use-case scenarios.