
Product
Socket for Jira Is Now Available
Socket for Jira lets teams turn alerts into Jira tickets with manual creation, automated ticketing rules, and two-way sync.
bigdecimal.js
Advanced tools
BigInt based BigDecimal implementation for Node.js 10.4 and above. This implementation is inspired from java BigDecimal class. This implementation is faster than popular big decimal libraries for most operations. See benchmarks results part below for comparison of each operation.
npm install bigdecimal.js
const { Big } = require('bigdecimal.js');
// Single constructor for all values
// Construct from a string and copy it
const x = Big('1.1111111111111111111111');
const y = new Big(x); // you can also use 'new'
const z = x.add(y);
console.log(z.toString()); // 2.2222222222222222222222
// You can also construct from a number or BigInt:
const u = Big(1.1);
const v = Big(2n);
console.log(u.toString()); // 1.1
console.log(v.toString()); // 2
You can use MathContext to set precision and rounding mode for a specific operation:
const { Big, MC, RoundingMode } = require('bigdecimal.js');
const x = Big('1');
const y = Big('3');
const res1 = x.divide(y, MC(3)); // MC is MathContext constructor that can be used without `new`
console.log(res1.toString()); // 0.333
const res2 = x.divide(y, new MC(3, RoundingMode.UP));
console.log(res2.toString()); // 0.334
try {
x.divide(y);
// throws since full precision is requested but it is not possible
} catch (e) {
console.log(e); // RangeError: Non-terminating decimal expansion; no exact representable decimal result.
}
npm inpm run compilenpm testThere is a benchmark suite that compares
To run the benchmark run npm install and then npm run benchmark.
For now, benchmarked against big.js and bigdecimal.
Test Machine:
Update Date: 01 August 2021
Each operation is run with fixed set of decimal numbers composed of both simple and complex numbers.
Micro benchmark framework used is benchmark. Check out benchmarks folder for source code of benchmarks.
For now, benchmarked the following operations, all operations will be added soon.
Operations per second(op/s):
| Operation | Bigdecimal.js | Big.js | GWT | Winner |
|---|---|---|---|---|
| Add | 47,477 | 12,340 | 55.58 | BigDecimal.js |
| Multiply | 336,782 | 31,950 | 1,451 | BigDecimal.js |
| Subtract | 43,147 | 11,678 | 54.10 | BigDecimal.js |
| Divide | 9,536 | 1,053 | 341 | BigDecimal.js |
| Abs | 506,144 | 937,951 | 7,992 | Big.js |
| Compare | 401,047 | 935,592 | 632,812 | Big.js |
| Remainder | 5,511 | 4,275 | 1,316 | BigDecimal.js |
FAQs
A BigDecimal implementation with native BigInts
The npm package bigdecimal.js receives a total of 1,437 weekly downloads. As such, bigdecimal.js popularity was classified as popular.
We found that bigdecimal.js demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Product
Socket for Jira lets teams turn alerts into Jira tickets with manual creation, automated ticketing rules, and two-way sync.

Company News
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.

Security News
NIST will stop enriching most CVEs under a new risk-based model, narrowing the NVD's scope as vulnerability submissions continue to surge.