It is often recommended1 to handle money as an integer representing the number of cents: 2572 cents instead of 25.72 dollars. This is to avoid the problems with floating-point arithmetic that you mention. Fortunately integer arithmetic in floating point is exact, so decimal representation errors can be avoided by scaling.


1Douglas Crockford: JavaScript: The Good Parts: Appendix A - Awful Parts (page 105).

Answer from Daniel Vassallo on Stack Overflow
🌐
Mikemcl
mikemcl.github.io › decimal.js
decimal.js API
An arbitrary-precision Decimal type for JavaScript.
🌐
npm
npmjs.com › package › decimal.js
decimal.js - npm
x = new Decimal(-12345.67); x.d // [ 12345, 6700000 ] digits (base 10000000) x.e // 4 exponent (base 10) x.s // -1 sign · For further information see the API reference in the doc directory. To run the tests using Node.js from the root directory:
      » npm install decimal.js
    
Published   Jul 06, 2025
Version   10.6.0
Author   Michael Mclaughlin
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Number › toFixed
Number.prototype.toFixed() - JavaScript | MDN
js · (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 point.
🌐
GitHub
github.com › MikeMcl › decimal.js
GitHub - MikeMcl/decimal.js: An arbitrary-precision Decimal type for JavaScript · GitHub
An arbitrary-precision Decimal type for JavaScript. ... The library is similar to bignumber.js, but here precision is specified in terms of significant digits rather than decimal places, and all calculations are rounded to the precision (similar ...
Author   MikeMcl
🌐
GitHub
github.com › tc39 › proposal-decimal
GitHub - tc39/proposal-decimal: Built-in exact decimal numbers for JavaScript · GitHub
Historically, JavaScript may not ... 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 conver...
Author   tc39
🌐
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
The light version of decimal.js, an arbitrary-precision Decimal type for JavaScript. - MikeMcl/decimal.js-light
Author   MikeMcl
🌐
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. There are multiple ways to round numbers. Check the last section on the configuration options for the rounding mode. Corticon.js is used to implement low-code/no-code decision services.
Find elsewhere
🌐
Zipy
zipy.ai › blog › how-to-round-to-at-most-two-decimal-places-in-javascript
how to round to at most two decimal places in javascript
April 12, 2024 - The most straightforward approach to round a number to two decimal places in JavaScript is using the toFixed() method.
🌐
W3Schools
w3schools.com › js › js_numbers.asp
W3Schools.com
By default, JavaScript displays numbers as base 10 decimals.
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › how-to-format-a-number-with-two-decimals-in-javascript
How to Format a Number with Two Decimals in JavaScript? - GeeksforGeeks
July 23, 2025 - In this approach we are using the toFixed() method. This method formats a number using fixed-point notation. It converts the number to a string and keep a specified number of decimals.
🌐
Adripofjavascript
adripofjavascript.com › blog › drips › avoiding-problems-with-decimal-math-in-javascript.html
Avoiding Problems with Decimal Math in JavaScript - A Drip of JavaScript
In JavaScript all numbers are IEEE 754 floating point numbers. Due to the binary nature of their encoding, some decimal numbers cannot be represented with perfect accuracy. This is analagous to how the fraction 1/3 cannot be accurately represented with a decimal number with a finite number ...
🌐
Atomic Spin
spin.atomicobject.com › javascript-math-precision-decimals
Precision Decimal Math in JavaScript with decimal.js
January 4, 2016 - To solve this issue, we can take one of two paths: We can use Math.round() to create incantations that we hope will toss out those miniscule fractions of pennies at exactly the right time, or we can use a decimal library.
🌐
cdnjs
cdnjs.com › home › libraries › decimal.js › 9.0.0
decimal.js - Libraries - cdnjs - The #1 free and open source CDN built to make life easier for developers
decimal.js · 9.0.0 · An arbitrary-precision Decimal type for JavaScript. 7k · GitHub · package · MIT licensed · https://mikemcl.github.io/decimal.js/ Tags: arbitrary, precision, arithmetic, big, number, decimal, float, biginteger, bigdecimal, ...
🌐
GitHub
github.com › Agrora › decimal-js
GitHub - Agrora/decimal-js: DecimalJS is an arbitrary precision floating point arithmetic library based on PHP's bcmath extension.
DecimalJS is an arbitrary precision floating point arithmetic library based on PHP's bcmath extension. - Agrora/decimal-js
Author   Agrora
🌐
DEV Community
dev.to › lucaspereiradesouzat › decimal-javascripts-future-numeric-type-1905
Decimal: JavaScript's future numeric type - DEV Community
December 29, 2025 - JavaScript utilizes the IEEE 754 standard for representing double-precision (64-bit) floating-point numbers. While efficient for most use cases, this representation can lead to subtle inaccuracies in certain operations.