big.js
A small, fast, dependency-free JavaScript library for arbitrary-precision decimal arithmetic.
Repository Health
Technical Analysis
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
Bigconstructor accepting a primitive number, numeric string, or another Big, usable with or withoutnew - 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) andBig.RM(rounding mode) properties controlling division, sqrt, and negative-exponent pow results - An optional
Big.strictmode 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
Ghostfolio
Invoicing Finance
Track your stocks, ETFs, and crypto with a privacy-first, self-hostable wealth management platform built for data-driven investors.
HeyForm
Forms Surveys · No Code Platforms
Open-source conversational form builder with AI generation, conditional logic, and 30+ integrations — self-host with full data ownership.
Lightdash
Analytics · Data Engineering
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.
Mastra Code
AI Code Assistants
"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.
NocoBase
No Code Platforms · Low Code Platforms
Open-source AI + no-code platform that lets coding agents and people collaborate to build business systems fast on proven infrastructure.
Polar
Ecommerce · Developer Tools · Invoicing Finance
Open source payments infrastructure that turns software into a business — subscriptions, usage-based billing, digital products, and merchant-of-record compliance in one platform.