# decimal.js

> An arbitrary-precision Decimal type for JavaScript

Source: https://talira.ai/catalog/decimal-js-an9hj0b5
Every listing: https://talira.ai/catalog.md

- Kind: Open source
- Types: Library
- Categories: [libraries / math / decimal arithmetic](https://talira.ai/categories/libraries/math/decimal-arithmetic), [languages / javascript](https://talira.ai/categories/languages/javascript)
- Licence: MIT[^1]
- Pricing: Free and open source[^1]
- Free tier: yes[^1]
- Self-hostable: yes[^2]
- API: yes[^2]
- Creator: Michael Mclaughlin (MikeMcl), who also wrote bignumber.js and big.js

decimal.js gives JavaScript an arbitrary-precision `Decimal` type, so `0.3 - 0.1` comes out as exactly 0.2 instead of suffering binary floating-point error. Precision is set in significant digits and every operation is rounded to it with a chosen rounding mode, as in Python's decimal module; it replicates most of `Number.prototype` and `Math`, adds trigonometric functions, non-integer powers and `toFraction`, and accepts hexadecimal, binary and octal values. It has no dependencies, ships as one script or an ES module with a [TypeScript](https://talira.ai/catalog/typescript-w0asrgz8.md) declaration file, and math.js uses it under the hood. Its author also maintains the smaller bignumber.js and big.js, and decimal.js-light, which drops the trigonometric functions.

## Links

- Website: https://mikemcl.github.io/decimal.js/
- GitHub: https://github.com/MikeMcl/decimal.js
- Docs: https://mikemcl.github.io/decimal.js/

## Problems it solves

- 0.1 + 0.2 isn't 0.3 in JavaScript and my order totals are off by a cent
- do exact decimal math for prices, taxes and invoices in the browser
- calculate with numbers too big or too precise for a JavaScript Number without losing digits
- control the rounding mode and precision of financial calculations in Node.js
- compute square roots, powers and logarithms to 50 significant digits
- sine, cosine and other trig functions with arbitrary precision in JS
- turn a decimal result into a fraction like 355/113
- parse hexadecimal or binary strings with fractional parts into exact numbers
- use different precision settings for different calculations in the same app
- a big-number type with no dependencies that runs even in very old JavaScript engines

## Features

- arbitrary-precision integers and decimals
- precision in significant digits with configurable rounding modes
- most Number.prototype and Math methods
- trigonometric, exponential and logarithmic functions
- non-integer powers and square roots
- toFraction with an optional maximum denominator
- hexadecimal, binary and octal input and output
- independent Decimal constructors with their own settings
- immutable values with chainable methods
- no dependencies; ECMAScript 3 only
- script file and ES module, with a TypeScript declaration file

## Capabilities

- Has an API: plan not known

## Trust

Overall: 0.28 out of 1.
Signals: backing 0.20, extensibility 0.20.

- created by Michael Mclaughlin (MikeMcl), who also wrote bignumber.js and big.js

Warnings:

- GitHub activity not fetched yet

## Sources

[^1]: https://github.com/MikeMcl/decimal.js/blob/master/LICENCE.md (checked 20 Nov 2026)
[^2]: https://github.com/MikeMcl/decimal.js (checked 20 Nov 2026)
