whatisgithub

What is bignumber.js?

mikemcl/bignumber.js — explained in plain English

Analysis updated 2026-06-24

6,999JavaScriptAudience · developerComplexity · 2/5Setup · easy

In one sentence

JavaScript library for precise arithmetic with numbers of any size or precision, fixing the silent rounding errors that occur with JavaScript's built-in number type for large values, small decimals, and non-base-10 numbers.

Mindmap

mindmap
  root((bignumber.js))
    What it solves
      Floating point errors
      Very large numbers
      Any base arithmetic
    API
      BigNumber constructor
      plus minus times
      Immutable results
    Formats
      CommonJS module
      ES module
      Browser global
    Related libraries
      big.js simpler
      decimal.js advanced
      Same author
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

What do people build with it?

USE CASE 1

Handle money amounts in a financial app without rounding errors like 0.1 + 0.2 producing the wrong result

USE CASE 2

Work with very large integer IDs or cryptocurrency balances that exceed JavaScript's safe integer range

USE CASE 3

Do arithmetic in binary, hexadecimal, or any base from 2 to 36 with full precision

What is it built with?

JavaScript

How does it compare?

mikemcl/bignumber.jshexgrad/kokorojsfiddle/togetherjs
Stars6,9997,0007,007
LanguageJavaScriptJavaScriptJavaScript
Setup difficultyeasymoderateeasy
Complexity2/52/52/5
Audiencedeveloperdeveloperdeveloper

Figures from each repo's GitHub metadata at analysis time.

How do you get it running?

Difficulty · easy Time to first run · 5min

So what is it?

bignumber.js is a JavaScript library that solves a precision problem built into the language. JavaScript's built-in number type can only represent about 15 to 17 significant decimal digits accurately, and calculations involving very large numbers, very small numbers, or repeating decimals quietly produce wrong results. This library provides a BigNumber type that can handle numbers of any size or precision without those rounding errors. The classic example is that in plain JavaScript, 0.1 plus 0.2 does not equal 0.3 due to how floating-point arithmetic works at the binary level. With bignumber.js, the same calculation returns the correct result. The library handles integers, decimals, and numbers in bases from 2 to 36, so you can work with binary, hexadecimal, or arbitrary-base values with full precision. Using the library means wrapping numbers in a BigNumber constructor rather than using JavaScript's native number literals. Once wrapped, you call methods like plus, minus, times, dividedBy, and modulo to do arithmetic. The results are also BigNumber objects, so you can chain operations. When you need a plain string or number back, you call toString or toFixed. BigNumber objects are immutable, meaning any operation returns a new value rather than changing the original. The library has no dependencies and weighs about 8 KB after minification and compression. It works in browsers, Node.js, and Deno, and ships in CommonJS, ES module, and browser-global formats. It mirrors several formatting methods from JavaScript's native Number type, including toExponential, toFixed, and toPrecision, which makes it a close drop-in for code that already uses those. The same author maintains two related libraries: big.js, which is smaller and covers only basic decimal arithmetic, and decimal.js, which adds support for things like non-integer exponents and lets you set a global precision limit for all operations.

Copy-paste prompts

Prompt 1
Using bignumber.js, rewrite this JavaScript function that calculates a running total of prices so it avoids all floating-point rounding errors
Prompt 2
Show me how to use bignumber.js to add, subtract, multiply, and format a result to exactly 2 decimal places without any rounding surprises
Prompt 3
I'm storing cryptocurrency amounts as strings to preserve precision, how do I use bignumber.js to safely add and compare these values?
Prompt 4
Replace the native JavaScript Math operations in this snippet with bignumber.js equivalents and explain what changed and why

Frequently asked questions

What is bignumber.js?

JavaScript library for precise arithmetic with numbers of any size or precision, fixing the silent rounding errors that occur with JavaScript's built-in number type for large values, small decimals, and non-base-10 numbers.

What language is bignumber.js written in?

Mainly JavaScript. The stack also includes JavaScript.

How hard is bignumber.js to set up?

Setup difficulty is rated easy, with roughly 5min to a first successful run.

Who is bignumber.js for?

Mainly developer.

Open on GitHub → Ask about another repo

This repo across BitVibe Labs

Verify against the repo before relying on details.