decimal.js

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

Library
npm
v10.6.0
7,243stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
51/100Fair
Development Activity40
Maintenance8
Community56
Maturity60
Momentum40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
74/100Good
Architecture78
Code Quality82
Innovation65
Learning Curve70

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

Low Code Platforms · Databases

15,526

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

View details
53
Repo Health
77
Technical
60
Dependency
Built with
TypeScript72%
Java22%
Updated 9 months ago
TypeScript
96%
Other

Amplication

Developer Tools · AI Code Assistants · Automation

16,010

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
61
Repo Health
84
Technical
60
Dependency
Built with
TypeScript96%
Updated 1 months ago
Java
78%
GPL 3.0

DataEase

Analytics · Data Engineering · AI Assistants

24,346

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
66
Dependency
Built with
Java78%
Vue22%
Updated yesterday
TypeScript
50%
Other

Dify

No Code Platforms · AI Development · Developer Tools

152,883

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

View details
92
Repo Health
85
Technical
71
Dependency
Built with
TypeScript50%
Python47%
Updated yesterday
TypeScript
97%
Other

GrowthBook

Developer Tools · Analytics · Monitoring

8,138

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
66
Dependency
Built with
TypeScript97%
Updated yesterday
TypeScript
99%
MIT

KeystoneJS

CMS · Developer Tools

9,957

The superpowered headless CMS for developers built with GraphQL and React

View details
91
Repo Health
81
Technical
64
Dependency
Built with
TypeScript99%
Updated 2 days ago
TypeScript
98%
Other

Langfuse

AI Development · Monitoring

33,366

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
66
Dependency
Built with
TypeScript98%
Updated yesterday
JavaScript
44%
Other

LimeSurvey

Forms Surveys

3,698

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
62
Dependency
Built with
JavaScript44%
PHP34%
CSS12%
Updated yesterday
TypeScript
95%
Other

LLM Gateway

AI Development · Devops

1,555

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

View details
85
Repo Health
80
Technical
72
Dependency
Built with
TypeScript95%
Updated yesterday

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