JavaScript math libraries

Updated Nov 2026

JavaScript math libraries add number types and operations that the built-in Number type cannot represent exactly. A decimal library stores each value as digits with a set precision rather than as a binary floating-point number. These libraries let payment systems, accounting tools, and scientific apps calculate prices, fractions, and large integers without rounding errors.

Popularity

decimal.js has the most monthly downloads in this comparison, at 522.7M.

LibraryMonthly downloadsStarsLast releaseLicense
decimal.js
536.3M
7.3KJul 2025MIT
long.js
502.9M
920Apr 2025Apache-2.0
bignumber.js
345.6M
7.0KJul 2026MIT
BN.js
307.7M
1.2KJul 2026MIT
Fraction.js
272.5M
696Aug 2025MIT
decimal.js-light
246.7M
411Sep 2020MIT
big.js
167.8M
5.2KApr 2025MIT
Math.js
21.3M
15.1KApr 2026Apache-2.0
Downloads: npm, last thirty days. Stars and releases: GitHub. Amber: no release in over a year.

Features compared

LibraryGlobal decimal precisionExact rational typeExpression evaluationBitwise operations
decimal.jsBuilt-inUnsupportedUnsupportedUnsupported
long.jsUnsupportedUnsupportedUnsupportedBuilt-in
bignumber.jsBuilt-inUnsupportedUnsupportedUnsupported
BN.jsUnsupportedUnsupportedUnsupportedBuilt-in
Fraction.jsUnsupportedBuilt-inUnsupportedUnsupported
decimal.js-lightBuilt-inUnsupportedUnsupportedUnsupported
big.jsBuilt-inUnsupportedUnsupportedUnsupported
Math.jsBuilt-inBuilt-inBuilt-inBuilt-in
Built-inNot supported

Libraries and code examples

Provides arbitrary-precision decimal arithmetic for JavaScript.

Downloads / mo
536.3M
Stars
7.3K
Last release
10.6.0
License
MIT

Strengths

  • Controls significant-digit precision. Round arithmetic to a configured number of significant digits.
  • Provides decimal scientific functions. Use trigonometry and non-integer powers with decimal values.

Limitations

  • Number inputs can lose digits. Pass long decimal values as strings to preserve their input digits.
  • Precision applies across arithmetic. Account for rounding after operations beyond division.

Quickstart

From README.md
$ npm install decimal.js
import Decimal from 'decimal.js';
const value = new Decimal('0.1');
console.log(value.plus('0.2').toString());

decimal.js examples

From open-source projects on GitHub

Represents a 64-bit two's-complement integer value as a Long class.

Downloads / mo
502.9M
Stars
920
Last release
5.3.2
License
Apache-2.0

Quickstart

From README.md
$ npm install long
import Long from 'long';
const value = Long.fromString('9007199254740993');
console.log(value.add(1).toString());

Provides arbitrary-precision decimal and non-decimal numeric arithmetic.

Downloads / mo
345.6M
Stars
7.0K
Last release
11.1.5
License
MIT

Strengths

  • Handles multiple number bases. Create values in decimal or another specified number base.
  • Preserves exact basic arithmetic. Arithmetic outside division-related operations returns exact results.

Limitations

  • Number inputs can lose digits. Create high-precision values from strings instead of native numbers.
  • Division uses configured decimal places. Set DECIMAL_PLACES and ROUNDING_MODE for division-related results.

Quickstart

From README.md
$ npm install bignumber.js
import BigNumber from 'bignumber.js';
const value = new BigNumber('0.1');
console.log(value.plus('0.2').toString());

bignumber.js examples

From open-source projects on GitHub
export const convertAmountFromNativeValue = (
  value: BigNumberish,
  priceUnit: BigNumberish | null,
  decimals = 18
): string => {
  if (isNil(priceUnit) || isZero(priceUnit)) return '0';
  return new BigNumber(new BigNumber(value).dividedBy(priceUnit).toFixed(decimals, BigNumber.ROUND_DOWN)).toFixed();
};

Implements big number arithmetic in pure JavaScript.

Downloads / mo
307.7M
Stars
1.2K
Last release
5.2.5
License
MIT

Quickstart

From README.md
$ npm install bn.js
const BN = require('bn.js');
const a = new BN('dead', 16);
const b = new BN('beef', 16);
console.log(a.add(b).toString(16));

BN.js examples

From open-source projects on GitHub

Provides exact rational number arithmetic.

Downloads / mo
272.5M
Stars
696
Last release
5.3.4
License
MIT

Quickstart

From README.md
$ npm install fraction.js
const Fraction = require('fraction.js');
const value = new Fraction(1, 3);
console.log(value.add(1, 6).toFraction());

Fraction.js examples

From open-source projects on GitHub

decimal.js-light

Provides an arbitrary-precision Decimal type for JavaScript.

Downloads / mo
246.7M
Stars
411
Last release
2.5.1
License
MIT

Quickstart

From README.md
$ npm install decimal.js-light
import Decimal from 'decimal.js-light';
const value = new Decimal('2');
console.log(value.dividedBy('3').toString());

decimal.js-light examples

From open-source projects on GitHub

Provides arbitrary-precision decimal arithmetic through a small numeric API.

Downloads / mo
167.8M
Stars
5.2K
Last release
7.0.1
License
MIT

Strengths

  • Preserves exact basic arithmetic. Addition, subtraction, and multiplication return exact decimal results.
  • Offers strict numeric conversion. Enable strict mode to reject imprecise conversions to native numbers.

Limitations

  • Division still requires rounding. Set DP and RM for division, square roots, and negative powers.

Quickstart

From README.md
$ npm install big.js
import Big from 'big.js';
const value = new Big('0.1');
console.log(value.plus('0.2').toString());

big.js examples

From open-source projects on GitHub

Provides a mathematics library for JavaScript and Node.js.

Downloads / mo
21.3M
Stars
15.1K
Last release
15.2.0
License
Apache-2.0

Strengths

  • Evaluates expressions with units. Convert measurement units inside mathematical expressions.
  • Supports configurable decimal precision. Configure BigNumber as the default numeric type for expression evaluation.

Limitations

  • BigNumber support varies by function. The random function does not support BigNumber values.
  • Heavy expressions need worker isolation. Evaluate heavy expressions in a worker that can be terminated.

Quickstart

From README.md
$ npm install mathjs
import {create, all} from 'mathjs';
const math = create(all);
console.log(math.evaluate('sqrt(3^2 + 4^2)'));

Math.js examples

From open-source projects on GitHub

FAQ

decimal.js suits decimal arithmetic with a configurable precision. Fraction.js suits exact rational values. Math.js suits apps that evaluate math expressions with units, matrices, and complex numbers.

A decimal library such as decimal.js or big.js stores values as decimal digits. Calculations then round only at the precision the code sets.

Math.js is a math library for JavaScript and Node.js with an expression parser. It supports units, matrices, complex values, and several numeric types.

JavaScript has a built-in BigInt type for integers of any size. BN.js and long.js offer integer classes with their own APIs, including bitwise operations.

decimal.js offers a larger API with significant-digit rounding. big.js keeps a smaller decimal API with precision controls focused on division.

For coding agents

Found your math library? Help your agent use it.

Connect Exa so your coding agent can find the library’s documentation, check its API, and look up implementations while you build.

Run in your terminal

claude plugin install exa@claude-plugins-official