Why 0.1 + 0.2 is not 0.3

The sign, exponent and mantissa bits of 0.1 + 0.2, and the exact value it stores.

Stored value and bits

Examples

Note

Both numbers are rounded when stored, and the sum is rounded again. The result is the double just above 0.3, so 0.1 + 0.2 === 0.3 is false. Compare with a tolerance, or count in whole cents.

Other notable values