Why does 0.1 + 0.2 !== 0.3 in JavaScript?

  • JavaScript has floating-point precision limitations
  • 0.1 and 0.2 are not stored precisely in binary
  • It's a bug in JavaScript
  • JavaScript uses a different numeric system
In JavaScript, numbers are represented in binary, and not all decimal fractions can be precisely represented in binary. Due to this limitation, when you perform operations like addition with decimal numbers, you might encounter tiny rounding errors that make 0.1 + 0.2 !== 0.3. This behavior is not unique to JavaScript and occurs in many programming languages with floating-point arithmetic.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *