What’s the result of the equality check?

Submitted 3 years, 5 months ago
Ticket #270
Views 211
Language/Framework Javascript
Priority Low
Status Closed

0.1 + 0.2 === 0.3 // => ???
Submitted on Oct 28, 20
add a comment

1 Answer

Verified

First, let’s look at the value of 0.1 + 0.2:

0.1 + 0.2; // => 0.30000000000000004

The sum of 0.1 and 0.2 numbers is not exactly 0.3, but slightly above 0.3.

Due to how floating point numbers are encoded in binary, operations like addition of floating point numbers are subject to rounding errors.

Simply put, comparing floats directly is not precise.

Thus 0.1 + 0.2 === 0.3 is false.

Submitted 3 years, 5 months ago


Latest Blogs