big.js

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

Library
npm
v7.0.1
5,198stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
41/100Fair
Development Activity0
Maintenance0
Community64
Maturity60
Momentum40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
73/100Good
Architecture78
Code Quality72
Innovation55
Learning Curve85

big.js provides a single Big constructor for representing and operating on decimal numbers with arbitrary precision, avoiding the rounding errors that come from JavaScript’s native floating-point Number type. Values are immutable, stored internally as a coefficient/exponent/sign triple, and every arithmetic method (plus, minus, times, div, mod, sqrt, pow, comparisons) returns a new Big so calls can be chained.

The library ships as a single ~6KB minified file with zero dependencies, works in any ECMAScript 3 environment (so all browsers, old and new, plus Node.js and Deno), and mirrors the toExponential, toFixed, and toPrecision methods JavaScript numbers already expose. Configurable DP (decimal places) and RM (rounding mode) properties control the precision of division-based operations, and an optional strict mode disallows constructing a Big from an imprecise primitive number.

What You Get

  • A single Big constructor accepting a primitive number, numeric string, or another Big, usable with or without new
  • Chainable arithmetic methods (plus/add, minus/sub, times, div, mod, sqrt, pow) that always return a new, immutable Big
  • Comparison methods (cmp, eq, gt, gte, lt, lte) for exact decimal comparisons
  • Number-like formatting methods (toExponential, toFixed, toPrecision, toString, round) matching JavaScript’s native Number API
  • Configurable global Big.DP (decimal places) and Big.RM (rounding mode) properties controlling division, sqrt, and negative-exponent pow results
  • An optional Big.strict mode that throws instead of silently losing precision when constructing from an imprecise primitive

Common Use Cases

  • Financial and monetary calculations where floating-point rounding errors (like 0.1 + 0.2 !== 0.3) are unacceptable
  • Cryptocurrency and blockchain applications working with amounts that exceed safe integer/float precision
  • E-commerce carts and invoicing logic that must sum, discount, and tax prices exactly
  • Scientific or engineering calculators that need exact decimal arithmetic in the browser
  • Form and UI libraries that need to format large or precise numeric input without native Number coercion

Under The Hood

Architecture big.js is a single self-contained module (big.js for CommonJS, big.mjs for ESM, kept in sync as parallel builds) built around one exported Big constructor function and a shared prototype object P. Editable module-level defaults (DP, RM, MAX_DP, MAX_POWER, NE, PE, STRICT) are copied onto the Big constructor itself as static properties (Big.DP, Big.RM, etc.), so every instance created from that constructor reads the same live configuration — a simple, flat design with no classes, no internal dependency graph, and nothing that breaks if consumers only touch the documented constructor and prototype methods. Numbers are stored as an array-of-digits coefficient (c), an integer exponent (e), and a sign (s), and every arithmetic method operates on that representation directly and returns a fresh Big rather than mutating the receiver.

Tech Stack The library has zero runtime dependencies and targets ECMAScript 3, so it runs unmodified in Node.js (engines: "node": "*"), Deno (imported directly from a raw GitHub/unpkg URL), and any browser going back to legacy engines. It ships both a CommonJS build (big.js, main/browser fields) and a native ES module build (big.mjs, module/exports.import fields) from the same package, with no bundler or transpiler step required to consume either. Minification is handled externally via terser, and TypeScript users get types from the community-maintained @types/big.js package on DefinitelyTyped rather than a bundled .d.ts.

Code Quality Tests live under test/methods/, one file per public method (div.js, pow.js, round.js, sqrt.js, toFixed.js, etc.), run through a custom test/runner.js harness invoked via npm test rather than a third-party test framework like Jest or Mocha — a lightweight, dependency-free approach consistent with the library’s own zero-dependency philosophy. CI (.github/workflows/ci.yml) runs the suite across Node 8, 18, 20, and 22 on every push and PR to main, giving reasonable confidence the library’s ES3-era code keeps working on both very old and current runtimes. There is no TypeScript source and no linter/formatter config in the repo; error handling is explicit and minimal, throwing plain Error/TypeError objects prefixed with [big.js] for invalid input rather than swallowing or silently coercing bad values.

What Makes It Unique Unlike most arbitrary-precision libraries, big.js deliberately optimizes for minimalism over feature breadth: it exposes only the operations a decimal type strictly needs (no bitwise ops, no big-integer-specific API), keeps its entire implementation in one small file, and documents itself explicitly against its own sibling projects (bignumber.js and decimal.js) so users can pick the smallest tool that fits their precision and API needs. That single-file, dependency-free, ES3-compatible design is the whole value proposition rather than an implementation detail.

Used by 6 apps in this directory

TypeScript
76%
AGPL 3.0

Ghostfolio

Invoicing Finance

9,252

Track your stocks, ETFs, and crypto with a privacy-first, self-hostable wealth management platform built for data-driven investors.

View details
93
Repo Health
79
Technical
67
Dependency
Built with
TypeScript76%
HTML21%
Updated yesterday
TypeScript
95%
AGPL 3.0

HeyForm

Forms Surveys · No Code Platforms

8,965

Open-source conversational form builder with AI generation, conditional logic, and 30+ integrations — self-host with full data ownership.

View details
85
Repo Health
67
Technical
67
Dependency
Built with
TypeScript95%
Updated 1 weeks ago
TypeScript
96%
Other

Lightdash

Analytics · Data Engineering

6,119

The open-source Looker alternative that turns your dbt project's metrics and dimensions into governed, self-serve charts and dashboards — no license key required.

View details
93
Repo Health
84
Technical
64
Dependency
Built with
TypeScript96%
Updated yesterday
TypeScript
99%
Apache 2.0

Mastra Code

AI Code Assistants

27,743

"A coding agent that never compacts" — a terminal-based AI coding agent built on the Mastra framework, with Observational Memory instead of context compaction, multi-model support, and OAuth login for Claude Max or ChatGPT Plus.

View details
88
Repo Health
73
Technical
65
Dependency
Built with
TypeScript99%
Updated today
TypeScript
99%
Other

NocoBase

No Code Platforms · Low Code Platforms

24,071

Open-source AI + no-code platform that lets coding agents and people collaborate to build business systems fast on proven infrastructure.

View details
94
Repo Health
81
Technical
63
Dependency
Built with
TypeScript99%
Updated today
Python
65%
Apache 2.0

Polar

Ecommerce · Developer Tools · Invoicing Finance

10,240

Open source payments infrastructure that turns software into a business — subscriptions, usage-based billing, digital products, and merchant-of-record compliance in one platform.

View details
90
Repo Health
82
Technical
69
Dependency
Built with
Python65%
TypeScript28%
Updated today

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search