git404hub

what is decimal.js fr?

mikemcl/decimal.js — explained in plain English

Analysis updated 2026-06-24

7,179JavaScriptAudience · developerComplexity · 2/5Setup · easy

tl;dr

decimal.js is a JavaScript library for precise decimal arithmetic that eliminates the rounding errors built-in JavaScript numbers produce, making it reliable for money calculations, scientific computing, and anything needing exact decimal results.

vibe map

mindmap
  root((repo))
    What It Does
      Arbitrary precision math
      No rounding errors
      Chainable operations
    Operations
      Add subtract multiply
      Trig and logarithms
      Power and square root
    Inputs and Outputs
      Decimal strings
      Hex binary octal
      TypeScript types
    Use Cases
      Money calculations
      Scientific computing
      Precise formatting

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

what do people make with this?

VIBE 1

Calculate currency totals in a checkout or payment flow without floating-point rounding errors like 0.1 + 0.2 returning 0.30000000000000004

VIBE 2

Perform calculations that require more than 15 significant digits, such as scientific or financial computations, without losing precision

VIBE 3

Use trigonometric functions or logarithms at arbitrary precision in a JavaScript or Node.js application

what's the stack?

JavaScriptTypeScript

how it stacks up fr

mikemcl/decimal.jsnode-formidable/formidablecasperjs/casperjs
Stars7,1797,1787,174
LanguageJavaScriptJavaScriptJavaScript
Setup difficultyeasyeasyhard
Complexity2/52/52/5
Audiencedeveloperdeveloperdeveloper

Figures from each repo's GitHub metadata at analysis time.

how do i run it?

Difficulty · easy time til it works · 5min

in plain english

JavaScript's built-in numbers have a precision limit. Any number with more than about 15 significant digits gets rounded, and some simple arithmetic produces unexpected results: 0.1 + 0.2 does not equal 0.3 in JavaScript. decimal.js is a library that solves this by providing an arbitrary-precision decimal type that can hold as many digits as needed and perform arithmetic without those rounding errors. You create a Decimal value by passing a number or string to the Decimal constructor. The library recommends using strings for anything with more than a few digits, because JavaScript may already lose precision when it parses a numeric literal. Once you have a Decimal, you can add, subtract, multiply, divide, and perform many other operations. The results are new Decimal values, the original is never modified. Methods can be chained, so a series of calculations can be written in one expression. The precision (number of significant digits to keep) and the rounding mode are configurable. You can create multiple Decimal constructors with different settings that operate independently, which is useful if different parts of a program need different levels of precision. The library includes trigonometric functions, logarithms, square roots, and power functions. It also handles hexadecimal, binary, and octal input and output. For a smaller build without the trigonometric functions, there is a companion package called decimal.js-light. decimal.js ships as both a regular JavaScript file and an ES module, so it works in browsers and in Node.js. It has no external dependencies and targets very old JavaScript environments (ECMAScript 3), making it compatible with a wide range of platforms. It includes a TypeScript declaration file for type-checked projects. The library is used internally by math.js, a larger mathematics library for JavaScript.

prompts (copy fr)

prompt 1
Show me how to use decimal.js to add 0.1 and 0.2 and reliably get exactly 0.3 instead of JavaScript's floating-point result
prompt 2
How do I configure decimal.js to use 50 significant digits of precision and set the rounding mode to banker's rounding for a financial app?
prompt 3
How do I use decimal.js in Node.js to format a price value with exactly two decimal places, rounding correctly in all edge cases?

Frequently asked questions

what is decimal.js fr?

decimal.js is a JavaScript library for precise decimal arithmetic that eliminates the rounding errors built-in JavaScript numbers produce, making it reliable for money calculations, scientific computing, and anything needing exact decimal results.

What language is decimal.js written in?

Mainly JavaScript. The stack also includes JavaScript, TypeScript.

How hard is decimal.js to set up?

Setup difficulty is rated easy, with roughly 5min to a first successful run.

Who is decimal.js for?

Mainly developer.

peek the repo → explain another one

This repo across BitVibe Labs

double-check against the repo, no cap.