big.js vs bignumber.js vs decimal.js-light
Precision Arithmetic Libraries for Financial and Scientific Data
big.jsbignumber.jsdecimal.js-lightSimilar Packages:

Precision Arithmetic Libraries for Financial and Scientific Data

JavaScript numbers follow the IEEE 754 standard, which causes rounding errors in decimal math β€” like adding 0.1 and 0.2. These libraries replace native numbers with objects that handle precise decimal arithmetic. They are essential for financial apps, scientific calculations, and any scenario where exact values matter more than raw speed.

Npm Package Weekly Downloads Trend

3 Years

Github Stars Ranking

Stat Detail

Package
Downloads
Stars
Size
Issues
Publish
License
big.js33,912,9155,19758.9 kB10a year agoMIT
bignumber.js07,011500 kB93 months agoMIT
decimal.js-light0410-66 years agoMIT

big.js vs bignumber.js vs decimal.js-light: Precision Math Compared

JavaScript uses floating-point numbers for all math, which leads to errors like 0.1 + 0.2 === 0.30000000000000004. For money or science, this is unacceptable. The big.js, bignumber.js, and decimal.js-light packages solve this by using arbitrary-precision decimal arithmetic. They look similar but differ in scope, configuration, and maintenance. Let's break down how they handle real-world tasks.

πŸ› οΈ Setup and Initialization

All three libraries require importing a class and creating instances from strings or numbers. Using strings is safer to avoid initial floating-point errors.

big.js uses a simple constructor with global configuration options.

import Big from 'big.js';

// Set global decimal places
Big.DP = 2;
Big.RM = 1;

const price = new Big('10.50');

bignumber.js offers a configurable constructor with a wider range of settings.

import BigNumber from 'bignumber.js';

// Configure precision and rounding
BigNumber.config({ DECIMAL_PLACES: 2, ROUNDING_MODE: 1 });

const price = new BigNumber('10.50');

decimal.js-light mimics the main decimal.js API with a similar setup.

import Decimal from 'decimal.js-light';

// Set precision globally
Decimal.set({ precision: 20 });

const price = new Decimal('10.50');

βž• Basic Arithmetic Operations

Performing math is the core use case. All three return new instances instead of changing the original value, which prevents side effects.

big.js uses short method names like times and div.

import Big from 'big.js';

const a = new Big('10');
const b = new Big('3');

const result = a.times(b).div(2);
// Returns Big object representing 15

bignumber.js prefers descriptive names like multipliedBy but supports aliases.

import BigNumber from 'bignumber.js';

const a = new BigNumber('10');
const b = new BigNumber('3');

const result = a.multipliedBy(b).dividedBy(2);
// Returns BigNumber object representing 15

decimal.js-light follows the decimal.js convention with times and div.

import Decimal from 'decimal.js-light';

const a = new Decimal('10');
const b = new Decimal('3');

const result = a.times(b).div(2);
// Returns Decimal object representing 15

🎯 Precision and Rounding Control

Handling decimal places and rounding modes is critical for financial reports. Each library handles this slightly differently.

big.js relies on global settings or method arguments for fixed output.

import Big from 'big.js';

const val = new Big('10.555');

// Uses global Big.DP setting
const fixed = val.toFixed(); 
// Or specify locally: val.toFixed(2)

bignumber.js allows per-operation rounding control with extensive options.

import BigNumber from 'bignumber.js';

const val = new BigNumber('10.555');

// Specify rounding mode directly
const fixed = val.decimalPlaces(2, BigNumber.ROUND_HALF_UP);

decimal.js-light supports similar per-operation control as the main library.

import Decimal from 'decimal.js-light';

const val = new Decimal('10.555');

// Specify rounding mode directly
const fixed = val.toDecimalPlaces(2, Decimal.ROUND_HALF_UP);

🌍 Scope and Feature Support

The libraries differ in what math they support beyond basic decimals. This affects whether they fit your project long-term.

big.js is strictly decimal. It does not support hex, binary, or complex exponents.

import Big from 'big.js';

// This works
const a = new Big('10.5');

// Non-decimal bases are NOT supported
// const b = new Big('ff', 16); // Throws error

bignumber.js supports multiple bases and advanced math functions.

import BigNumber from 'bignumber.js';

// Base 10 works
const a = new BigNumber('10.5');

// Base 16 (hex) also works
const b = new BigNumber('ff', 16);

decimal.js-light is decimal-focused like big.js but retains some decimal.js structure.

import Decimal from 'decimal.js-light';

// This works
const a = new Decimal('10.5');

// Non-decimal bases are generally NOT supported in light version
// const b = new Decimal('ff', 16); // Not supported

🧩 Maintenance and Ecosystem

Knowing who maintains the code helps you judge long-term reliability for production apps.

big.js is maintained by Michael Mcl, who also maintains bignumber.js. It is stable and receives security updates.

// Stable API, rarely changes
import Big from 'big.js';
// No major breaking changes in recent years

bignumber.js is also maintained by Michael Mcl. It is the most robust option with active development.

// Active development
import BigNumber from 'bignumber.js';
// Regular updates for edge cases

decimal.js-light is a community fork of decimal.js. It is less actively maintained than the main decimal.js project.

// Community maintained
import Decimal from 'decimal.js-light';
// Updates may lag behind main decimal.js project

πŸ“Š Summary: Key Similarities

While the differences matter, these libraries share core goals and behaviors.

1. πŸ”’ Arbitrary Precision

  • All three avoid IEEE 754 floating-point errors.
  • They handle very large or very small numbers accurately.
// All handle this without losing precision
// 0.1 + 0.2 === 0.3

2. πŸ”’ Immutability

  • Operations return new instances instead of modifying existing ones.
  • This prevents bugs caused by changing shared values.
const a = new Big('10');
const b = a.plus('5'); 
// 'a' is still 10, 'b' is 15

3. πŸ“ String Initialization

  • All recommend passing strings to avoid initial precision loss.
  • Passing numbers directly can introduce errors before math starts.
// Recommended
new Big('0.1');

// Risky
new Big(0.1);

4. πŸ› οΈ Formatting Output

  • All provide methods to convert back to strings or numbers.
  • Useful for displaying values in UI or sending to APIs.
val.toFixed(2);
val.toString();

πŸ†š Summary: Key Differences

Featurebig.jsbignumber.jsdecimal.js-light
MaintainerπŸ‘€ Michael MclπŸ‘€ Michael MclπŸ‘₯ Community Fork
Base SupportπŸ”’ Decimal OnlyπŸ”’ Decimal, Hex, Binary, etc.πŸ”’ Decimal Only
Method Names⚑ Short (times, div)πŸ“– Descriptive (multipliedBy)⚑ Short (times, div)
ConfigurabilityπŸ”§ BasicπŸ”§ AdvancedπŸ”§ Moderate
Bundle FootprintπŸŽ’ SmallπŸŽ’ LargerπŸŽ’ Medium
Best Use CaseπŸ’° Currency, Simple FormsπŸ”¬ Science, Crypto, Complex MathπŸ“± Existing decimal.js Users

πŸ’‘ The Big Picture

big.js is like a precision screwdriver πŸͺ› β€” small, focused, and perfect for specific jobs like currency math. Use it when you want reliability without extra weight.

bignumber.js is like a full mechanic's kit 🧰 β€” heavy but capable of handling any math problem you throw at it. Use it when you need flexibility or non-decimal bases.

decimal.js-light is like a compact travel kit πŸŽ’ β€” designed for those who know the main decimal.js tools but need to save space. Use it if you are already committed to that API style.

Final Thought: All three solve the floating-point problem effectively. For most frontend financial apps, big.js offers the best balance of size and stability. Choose bignumber.js only if you need its advanced features, and treat decimal.js-light as a niche option for specific bundle constraints.

How to Choose: big.js vs bignumber.js vs decimal.js-light

  • big.js:

    Choose big.js if you need strict decimal arithmetic for currency or fixed-point math with a minimal footprint. It is stable, maintained by the same author as bignumber.js, and focuses solely on base-10 operations without extra features. This makes it ideal for frontend forms or simple financial calculations where bundle size is a concern.

  • bignumber.js:

    Choose bignumber.js if you need advanced features like non-decimal bases (hex, binary), complex configuration, or support for very large numbers beyond standard decimals. It is the most flexible option and handles edge cases well, making it suitable for scientific apps or cryptography where math requirements vary widely.

  • decimal.js-light:

    Choose decimal.js-light if you need API compatibility with the full decimal.js library but require a smaller bundle size. Be aware that it is a community fork with less active development than the main decimal.js project. It works well for projects already standardized on the decimal.js API that need to optimize load times.

README for big.js

big.js

A small, fast JavaScript library for arbitrary-precision decimal arithmetic.

npm version npm downloads CI

Features

  • Simple API
  • Faster, smaller and easier-to-use than JavaScript versions of Java's BigDecimal
  • Only 6 KB minified
  • Replicates the toExponential, toFixed and toPrecision methods of JavaScript Numbers
  • Stores values in an accessible decimal floating point format
  • Comprehensive documentation and test set
  • No dependencies
  • Uses ECMAScript 3 only, so works in all browsers

The little sister to bignumber.js and decimal.js. See here for some notes on the difference between them.

Install

The library is the single JavaScript file big.js or the ES module big.mjs.

Browsers

Add Big to global scope:

<script src='path/to/big.js'></script>

ES module:

<script type='module'>
import Big from './path/to/big.mjs';

Get a minified version from a CDN:

<script src='https://cdn.jsdelivr.net/npm/[email protected]/big.min.js'></script>

Node.js

$ npm install big.js

CommonJS:

const Big = require('big.js');

ES module:

import Big from 'big.js';

Deno

import Big from 'https://raw.githubusercontent.com/mikemcl/big.js/v7.0.1/big.mjs';
import Big from 'https://unpkg.com/big.js@latest/big.mjs';

Use

In the code examples below, semicolons and toString calls are not shown.

The library exports a single constructor function, Big.

A Big number is created from a primitive number, string, or other Big number.

x = new Big(123.4567)
y = Big('123456.7e-3')                 // 'new' is optional
z = new Big(x)
x.eq(y) && x.eq(z) && y.eq(z)          // true

In Big strict mode, creating a Big number from a primitive number is disallowed.

Big.strict = true
x = new Big(1)                         // TypeError: [big.js] Invalid number
y = new Big('1.0000000000000001')
y.toNumber()                           // Error: [big.js] Imprecise conversion

A Big number is immutable in the sense that it is not changed by its methods.

0.3 - 0.1                              // 0.19999999999999998
x = new Big(0.3)
x.minus(0.1)                           // "0.2"
x                                      // "0.3"

The methods that return a Big number can be chained.

x.div(y).plus(z).times(9).minus('1.234567801234567e+8').plus(976.54321).div('2598.11772')
x.sqrt().div(y).pow(3).gt(y.mod(z))    // true

Like JavaScript's Number type, there are toExponential, toFixed and toPrecision methods.

x = new Big(255.5)
x.toExponential(5)                     // "2.55500e+2"
x.toFixed(5)                           // "255.50000"
x.toPrecision(5)                       // "255.50"

The arithmetic methods always return the exact result except div, sqrt and pow (with negative exponent), as these methods involve division.

The maximum number of decimal places and the rounding mode used to round the results of these methods is determined by the value of the DP and RM properties of the Big number constructor.

Big.DP = 10
Big.RM = Big.roundHalfUp

x = new Big(2);
y = new Big(3);
z = x.div(y)                           // "0.6666666667"
z.sqrt()                               // "0.8164965809"
z.pow(-3)                              // "3.3749999995"
z.times(z)                             // "0.44444444448888888889"
z.times(z).round(10)                   // "0.4444444445"

The value of a Big number is stored in a decimal floating point format in terms of a coefficient, exponent and sign.

x = new Big(-123.456);
x.c                                    // [1,2,3,4,5,6]    coefficient (i.e. significand)
x.e                                    // 2                exponent
x.s                                    // -1               sign

For advanced usage, multiple Big number constructors can be created, each with an independent configuration.

For further information see the API reference documentation.

Minify

To minify using, for example, npm and terser

$ npm install -g terser
$ terser big.js -c -m -o big.min.js

Test

The test directory contains the test scripts for each Big number method.

The tests can be run with Node.js or a browser.

Run all the tests:

$ npm test

Test a single method:

$ node test/toFixed

For the browser, see runner.html and test.html in the test/browser directory.

big-vs-number.html is a old application that enables some of the methods of big.js to be compared with those of JavaScript's Number type.

TypeScript

The DefinitelyTyped project has a Typescript type definitions file for big.js.

$ npm install --save-dev @types/big.js

Any questions about the TypeScript type definitions file should be addressed to the DefinitelyTyped project.

Licence

MIT

Contributors

Financial supporters

Thank you to all who have supported this project via Open Collective, particularly Coinbase.