decimal.js

An arbitrary-precision Decimal type for JavaScript with full trigonometric support

Library
npm
v10.6.0
7,261 stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
55 /100 Fair
Development Activity 48
Maintenance 16
Community 56
Maturity 60
Momentum 40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
74 /100 Good
Architecture 78
Code Quality 82
Innovation 65
Learning Curve 70

decimal.js provides an arbitrary-precision Decimal type for JavaScript, solving the well-known problem where native floating-point numbers produce results like 0.1 + 0.2 !== 0.3. It replicates most of the methods found on JavaScript’s Number.prototype and Math objects, but computes them to a configurable number of significant digits with predictable rounding, similar in spirit to Python’s decimal module.

Unlike its sibling libraries bignumber.js and big.js (also maintained by the same author), decimal.js additionally implements trigonometric and other advanced functions and supports non-integer powers, making it the largest and most feature-complete of the three — at the cost of a bigger bundle. It has zero dependencies, supports hex/binary/octal input, ships TypeScript declarations, and is used internally by math.js.

What You Get

  • An arbitrary-precision Decimal type supporting integers and floats with immutable, chainable methods
  • Full trigonometric and transcendental function support (sin, cos, atan, ln, exp, etc.) beyond basic arithmetic
  • Configurable precision and rounding per independently-clonable Decimal constructor via Decimal.clone({...})
  • Hexadecimal, binary, and octal number parsing and formatting alongside standard decimal
  • TypeScript declaration files and both CommonJS (decimal.js) and ESM (decimal.mjs) builds

Common Use Cases

  • Financial and monetary calculations where floating-point rounding errors are unacceptable
  • Scientific or engineering computations requiring more significant digits than JavaScript’s native Number can represent
  • Cryptography, cryptocurrency, or blockchain applications needing exact big-integer/big-decimal arithmetic
  • Powering higher-level math libraries (e.g. math.js uses decimal.js internally) that need a reliable arbitrary-precision numeric core

Under The Hood

Architecture - The library is a single ~4,950-line file (decimal.js, mirrored as decimal.mjs for ESM) implementing the Decimal constructor and its full method set. Internally each value is stored as a sign (s), an array of base-10,000,000 digit groups (d), and a base-10 exponent (e) — a classic floating-point-of-digits representation that avoids native float imprecision entirely. Every arithmetic method (plus, times, sqrt, trigonometric functions) operates on these digit arrays and rounds the result according to the constructor’s configured precision/rounding settings before returning a new immutable Decimal.

Tech Stack - Pure JavaScript (99.8%) written to run on ECMAScript 3 for maximum backward compatibility, with zero runtime dependencies. It ships prebuilt CommonJS, ESM, and global-script builds plus a .d.ts/.global.d.ts pair of TypeScript declarations, and includes example minification recipes for uglify-js and terser.

Code Quality - The test/modules/ directory contains 61 separate test modules, one per method (e.g. toFraction, sqrt, pow), runnable individually via node test/modules/<name> or all together via npm test, plus a browser test harness (test/test.html). Given the mathematical nature of the code, correctness is verified through large tables of expected input/output pairs per operation rather than typical unit-test mocking patterns.

API Design - The API deliberately mirrors JavaScript’s native Number.prototype/Math naming (toFixed, toPrecision, sqrt) so developers already familiar with JS numbers have minimal new vocabulary to learn, while method chaining (x.dividedBy(y).plus(z).times(9).floor()) keeps multi-step calculations readable. Most methods have short aliases (div/dividedBy, cmp/comparedTo), and the ability to create independently-configured constructors via Decimal.clone() is a thoughtful touch for libraries embedding decimal.js without polluting global config.

Used by 12 apps in this directory

TypeScript
72%
AGPL 3.0

APITable

Databases · Low Code Platforms

15,623

API-first collaborative spreadsheet-database platform that auto-generates REST APIs and lets teams build internal tools, CRMs, and dashboards without code.

View details
71
Repo Health
77
Technical
60
Dependency
Built with
TypeScript 72%
Java 22%
Updated 3 weeks ago
TypeScript
96%
Other

Amplication

AI Code Assistants · Automation · Developer Tools

16,015

Create production-ready backend services with your organization's standards baked in — generating NestJS, Prisma, and GraphQL code that you own and control.

View details
58
Repo Health
84
Technical
60
Dependency
Built with
TypeScript 96%
Updated 3 months ago
Java
70%
GPL 3.0

DataEase

AI Assistants · Analytics · Data Engineering

24,558

Open-source BI tool with drag-and-drop dashboards, 20+ data source connectors, and AI-powered natural language queries — a self-hosted alternative to Tableau.

View details
94
Repo Health
71
Technical
65
Dependency
Built with
Java 70%
Vue 29%
Updated 4 days ago
TypeScript
50%
Other

Dify

AI Development · Design Tools · Developer Tools

157,364

Visual LLM workflow platform with RAG pipelines, agent capabilities, and model management for building production AI applications.

View details
92
Repo Health
85
Technical
66
Dependency
Built with
TypeScript 50%
Python 47%
Updated 4 days ago
TypeScript
97%
Other

GrowthBook

Ab Testing Experimentation · Analytics · Developer Tools

8,446

Open source feature flags, A/B testing, and warehouse-native experimentation that queries your existing data infrastructure—no data movement required.

View details
92
Repo Health
85
Technical
63
Dependency
Built with
TypeScript 97%
Updated 4 days ago
TypeScript
99%
MIT

KeystoneJS

CMS · Developer Tools

9,982

The superpowered headless CMS for developers built with GraphQL and React

View details
92
Repo Health
81
Technical
64
Dependency
Built with
TypeScript 99%
Updated 4 days ago
TypeScript
97%
Other

Langfuse

AI Development · Monitoring

35,117

Open source AI engineering platform for LLM observability, prompt management, evaluation, and debugging — self-host in minutes or use Langfuse Cloud.

View details
92
Repo Health
81
Technical
65
Dependency
Built with
TypeScript 97%
Updated 4 days ago
JavaScript
43%
Other

LimeSurvey

Forms Surveys

3,736

The world's most flexible open-source survey platform with 900+ templates, conditional logic, 80+ languages, and full GDPR compliance for any scale.

View details
86
Repo Health
62
Technical
63
Dependency
Built with
JavaScript 43%
PHP 35%
CSS 12%
Updated 5 days ago
TypeScript
96%
Other

LLM Gateway

AI Development · Devops

1,663

One API endpoint for 25+ LLM providers — route, track costs, enforce compliance, and switch models without changing your code.

View details
86
Repo Health
80
Technical
68
Dependency
Built with
TypeScript 96%
Updated 5 days ago

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