SpinTheMic
Pro

Interview practice question

0.1 + 0.2 does not equal 0.3

Frontend Engineering · JavaScript Core · Beginner

Your code checks if 0.1 + 0.2 === 0.3, and it returns false. Why, and how do you handle it?

What a strong answer covers

Your AI report card counts how many of these ideas you cover.

  • Binary floating point can't represent some decimals exactly.
  • Result is 0.30000000000000004.
  • Compare with tolerance (Number.EPSILON).
  • Use integers (cents) for money.
  • Format for display with toFixed.
Practise this topic

Start without signing up. Sign in free to get an AI report card on your answer.

See all topics