🌐
Mikemcl
mikemcl.github.io › decimal.js
decimal.js API
An arbitrary-precision Decimal type for JavaScript. Hosted on GitHub. The library is incorporated into this page, so it should be available in the console now. See the README on GitHub for a quick-start introduction. In all examples below, var and semicolons are not shown, and if a commented-out value is in quotes it means toString has been called on the preceding expression.
🌐
GitHub
github.com › MikeMcl › decimal.js
GitHub - MikeMcl/decimal.js: An arbitrary-precision Decimal type for JavaScript · GitHub
const Decimal = require('decimal.js'); import Decimal from 'decimal.js'; import {Decimal} from 'decimal.js'; In all examples below, semicolons and toString calls are not shown.
Author   MikeMcl
🌐
Mikemcl
mikemcl.github.io › decimal.js-light
decimal.js-light API
The light version of decimal.js, an arbitrary-precision Decimal type for JavaScript. Hosted on GitHub. The library is incorporated into this page, so it should be available in the console now. See the README on GitHub for a quick-start introduction. In all examples below, var and semicolons ...
🌐
npm
npmjs.com › package › decimal.js
decimal.js - npm
const Decimal = require('decimal.js'); import Decimal from 'decimal.js'; import {Decimal} from 'decimal.js'; In all examples below, semicolons and toString calls are not shown.
      » npm install decimal.js
    
Published   Jul 06, 2025
Version   10.6.0
Author   Michael Mclaughlin
🌐
Medium
medium.com › @riteshsinha_62295 › front-end-dilemmas-tackling-precision-problems-in-javascript-with-decimal-js-c38a9ae24ddd
Front-End Dilemmas: Tackling Precision Problems in JavaScript with Decimal.js | by Ritesh Sinha | Medium
September 15, 2023 - Decimal.js allows you to perform precise arithmetic operations with decimal numbers, ensuring that you get the results you expect. Let’s look at some examples to highlight the benefits of Decimal.js.
🌐
GitHub
github.com › MikeMcl › decimal.js-light
GitHub - MikeMcl/decimal.js-light: The light version of decimal.js, an arbitrary-precision Decimal type for JavaScript. · GitHub
x = new Decimal(2); y = new Decimal(3); // decimal.js x.dividedBy(y).toString(); // '0.66666666666666666667' // decimal.js-light x.dividedBy(y).toString(); // '0.66666666666666666666' x.dividedBy(y).toDecimalPlaces(19).toString(); // ...
Author   MikeMcl
🌐
Snyk
snyk.io › advisor › decimal › functions › decimal.js.decimal
How to use the decimal.js.Decimal function in decimal | Snyk
static fromCoins = (amount, currency) => { currency = currency || {}; if (currency.precision === undefined) throw new Error('A valid currency must be provided'); if (amount instanceof BigNumber) amount = amount.toString(); amount = new Decimal(amount); amount = amount.div(Math.pow(10, currency.precision)); return new Money(amount, currency); }; wavesplatform / WavesExplorerLite / src / js / shared / OrderPrice.js View on Github
🌐
Progress
progress.com › blogs › decimals-no-limitations-javascript
Decimals with No Limitations in JavaScript
November 13, 2024 - Here is one last example to show rounding with large numbers: Decimal 1,234,567,890,123 multiplied by Decimal 1 will yield 123460000000. Here, rounding takes place at the 5th digit.
🌐
GitHub
github.com › tc39 › proposal-decimal
GitHub - tc39/proposal-decimal: Built-in exact decimal numbers for JavaScript · GitHub
Historically, JavaScript may not have been considered a language where exact decimal numbers are even exactly representable, with the understanding that doing calculations is bound to propagate any initial rounding errors when numbers were created. In some application architectures, JS only deals with a string representing a human-readable decimal quantity (e.g, "1.25"), and never does calculations or conversions.
Author   tc39
Find elsewhere
🌐
CodeSandbox
codesandbox.io › examples › package › decimal.js-light
decimal.js-light examples - CodeSandbox
Use this online decimal.js-light playground to view and fork decimal.js-light example apps and templates on CodeSandbox.
🌐
DEV Community
dev.to › lucaspereiradesouzat › decimal-javascripts-future-numeric-type-1905
Decimal: JavaScript's future numeric type - DEV Community
December 29, 2025 - // Example of using a Decimal library (simulated for educational purposes) // In a real scenario, you would use a library like 'decimal.js' or 'big.js' /** * Represents a decimal number with exact precision. * In a real implementation, this would be a class encapsulating the logic.
🌐
MojoAuth
mojoauth.com › binary-encoding-decoding › decimal-with-javascript-in-browser
Decimal with JavaScript in Browser | Binary Encoding Techniques Across Programming Languages
A common gotcha is assuming standard decimal arithmetic will always work flawlessly. This can cause bugs in financial applications or anywhere exact decimal representation is critical. To avoid this, consider using libraries like Decimal.js or Big.js for accurate calculations, or employ rounding ...
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › how-to-get-decimal-portion-of-a-number-using-javascript
How to get decimal portion of a number using JavaScript ? - GeeksforGeeks
July 11, 2025 - Example: This example subtracts the floor of the number by original number to get the decimal portion. But in this case, we'll get the exact portion after decimal.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Number › toFixed
Number.prototype.toFixed() - JavaScript | MDN
For example: ... (1000000000000000128).toString(); // '1000000000000000100' (1000000000000000128).toFixed(0); // '1000000000000000128' However, choosing a digits precision that's too high can return unexpected results, because decimal fractional numbers cannot be represented precisely in floating ...
🌐
MojoAuth
mojoauth.com › binary-encoding-decoding › decimal-with-nodejs
Decimal with NodeJS | Binary Encoding Techniques Across Programming Languages
When dealing with financial calculations or any scenario requiring high precision in NodeJS, it's crucial to avoid native JavaScript's floating-point inaccuracies. The decimal.js library provides dedicated methods for all standard arithmetic operations. You should consistently use .plus(), .minus(), .times(), and .dividedBy() for your calculations.