Algorithms and Data Structures · Senior · Question 49 of 75
Why does 0.1 + 0.2 !== 0.3 matter for algorithms?
- 1Numbers above 0.25 lose all of their precision
- 2JavaScript rounds every sum down to an integer
- ✓Correct answer: Float sums aren't exact, so compare with a tolerance
Explanation
Binary floating point can't represent 0.1 exactly, and errors accumulate in long sums or geometry code. Compare with Math.abs(a - b) < epsilon, use integers (cents instead of dollars), or BigInt for exact integer math.