From the Floating-Point Guide:

What can I do to avoid this problem?

That depends on what kind of calculations you’re doing.

  • If you really need your results to add up exactly, especially when you work with money: use a special decimal datatype.
  • If you just don’t want to see all those extra decimal places: simply format your result rounded to a fixed number of decimal places when displaying it.
  • If you have no decimal datatype available, an alternative is to work with integers, e.g. do money calculations entirely in cents. But this is more work and has some drawbacks.

Note that the first point only applies if you really need specific precise decimal behaviour. Most people don't need that, they're just irritated that their programs don't work correctly with numbers like 1/10 without realizing that they wouldn't even blink at the same error if it occurred with 1/3.

If the first point really applies to you, use BigDecimal for JavaScript or DecimalJS, which actually solves the problem rather than providing an imperfect workaround.

Answer from Michael Borgwardt on Stack Overflow
🌐
W3Schools
w3schools.com › js › js_numbers.asp
JavaScript Numbers
Real numbers (floating-point): float (32-bit), double (64-bit). Javascript numbers are always double (64-bit floating point).
🌐
Math.js
mathjs.org › docs › datatypes › numbers.html
math.js | an extensive math library for JavaScript and Node.js
Math.js uses the built-in JavaScript Number type. A Number is a floating point number with a limited precision of 64 bits, about 16 digits. The largest integer number which can be represented by a JavaScript Number is +/- 9007199254740992 (+/- 2^53). Because of the limited precision of floating ...
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › parseFloat
parseFloat() - JavaScript - MDN Web Docs
The parseFloat() function parses a string argument and returns a floating point number. function circumference(r) { return parseFloat(r) * 2.0 * Math.PI; } console.log(circumference(4.567)); // Expected output: 28.695307297889173 console.log(circumference("4.567abcdefgh")); // Expected output: ...
🌐
Fridoverweij
library.fridoverweij.com › docs › floating_points_in_js
Floating points in JavaScript
March 23, 2025 - Programming languages may even ... data types: number (floating points) and the more recent addition to the language BigInt (bignums). The number data type represents floating point numbers and is the general numeric data type for both integers and fractions....
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Math › floor
Math.floor() - JavaScript - MDN Web Docs
The Math.floor() static method always rounds down and returns the largest integer less than or equal to a given number.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Math › fround
Math.fround() - JavaScript - MDN Web Docs
July 10, 2025 - console.log(Math.fround(5.5)); // Expected output: 5.5 console.log(Math.fround(5.05)); // Expected output: 5.050000190734863 console.log(Math.fround(5)); // Expected output: 5 console.log(Math.fround(-5.05)); // Expected output: -5.050000190734863 ... The nearest 32-bit single precision float representation of doubleFloat. JavaScript uses 64-bit double floating-point numbers internally, which offer a very high precision.
Find elsewhere
🌐
SheCodes
shecodes.io › athena › 24061-what-is-a-float-in-javascript
[JavaScript] - What is a float in JavaScript? - SheCodes | SheCodes
Learn about the float data type in JavaScript and how it's used to represent numbers with a fractional part or very large/small numbers.
🌐
Medium
patrickkarsh.medium.com › why-math-is-hard-in-javascript-floating-point-precision-in-javascript-41706aa7a89d
Math is Hard in JavaScript: Floating-Point Precision in JavaScript | by Patrick Karsh | Medium
November 24, 2023 - This article delves into the common errors encountered in JavaScript’s floating-point arithmetic, providing examples to illustrate these quirks and offering insight into their underlying causes.
🌐
Reddit
reddit.com › r/javascript › [askjs] how do you deal with floats in production apps?
r/javascript on Reddit: [AskJS] How do you deal with floats in production apps?
August 13, 2022 -

We all know the 0.1 + 0.2 = 0.30000000000000004 and the precision issues with Javascript floats (IEEE-754). These problems are immediately visible (and applicable) to nearly all application which has number/floats (even simple calculation via JS) on both frontend and backend with Node.js/Deno.js/Bun.js etc.

How do you deal with the fact that the floating point, which is the result of a calculation, is represented exactly and is saved correctly in DB/REST api/front end etc.

🌐
CodeMag
codemag.com › article › 1811041 › JavaScript-Corner-Math-and-the-Pitfalls-of-Floating-Point-Numbers
JavaScript Corner: Math and the Pitfalls of Floating Point Numbers
August 31, 2022 - JavaScript performs arithmetic calculations with floating point numbers in a manner consistent with other programming languages. What's a developer to do? Does this mean if you have mathematical operations to perform, JavaScript is useless? Of course not. The real issue is floating point/double ...
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › how-to-add-float-numbers-using-javascript
Add float numbers using JavaScript - GeeksforGeeks
November 13, 2025 - JavaScript · let val = ... · Given two or more numbers, to sum up the float numbers. Use parseFloat() and Math.round() method to get the desired output....
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › floating-point-number-precision-in-javascript
Floating point number precision in JavaScript - GeeksforGeeks
July 11, 2025 - It is a double-precision format where 64 bits are allocated for every floating point. The displaying of these floating values could be handled using these methods: Table of Content ·
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Math › round
Math.round() - JavaScript - MDN Web Docs
console.log(Math.round(0.9)); // Expected output: 1 console.log(Math.round(5.95), Math.round(5.5), Math.round(5.05)); // Expected output: 6 6 5 console.log(Math.round(-5.05), Math.round(-5.5), Math.round(-5.95)); // Expected output: -5 -5 -6
🌐
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 ...
🌐
GitHub
gist.github.com › lsloan › f8c5ab552545ee968cca
JavaScript floating point math bug example · GitHub
for (i = 0.00; i <= 1.00; i = +((i + 0.01).toPrecision(2))) { // Note the final-expression in the for-loop limits decimal places, // overcoming float errors from adding 0.01 j = i * 100; if (Math.round(j) != j) { console.log('Multiplcation error:', i, j); } }
🌐
Modern Web
modernweb.com › frontend development › what every javascript developer should know about floating points
What Every JavaScript Developer Should Know About Floating Points | Modern Web - Web3, Business & Technology
May 5, 2023 - Imagine doing basic mathematics like 0.1 + 0.2, and the answer returns 0.2625! Fortunately, the floating point specification that ECMAScript uses specifies up to 52 mantissa, so the rounding errors are quite small – the specification specifically details the expected rounding errors for most numbers.
🌐
JavaScript.info
javascript.info › tutorial › the javascript language › data types
Numbers
December 18, 2024 - They “read” a number from a string until they can’t. In case of an error, the gathered number is returned. The function parseInt returns an integer, whilst parseFloat will return a floating-point number:
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › how-to-format-a-float-in-javascript
How to Format a Float in JavaScript? - GeeksforGeeks
July 12, 2025 - // Define the float value let n = 6.56759; let roundValue = Math.round(n); console.log("Math.round(n) =", roundValue); ... The JavaScript Math.round() method rounds a number to the nearest integer.