Floating Point Precision
Question
Why does `0.1 + 0.2` not equal `0.3` in JavaScript?
Hint
This happens in all languages that use IEEE 754 floating point.
Explanation
Computers store numbers in binary, and some decimal fractions (like 0.1) cannot be represented exactly in binary — similar to how 1/3 cannot be represented exactly in decimal. This causes tiny rounding errors: 0.1 + 0.2 = 0.30000000000000004. This is a fundamental limitation of floating-point arithmetic, not a bug. It affects all IEEE 754 languages.
Related Resources
Related Lessons
- Numbers and Math
Learn about numbers and math operations.
Look up unfamiliar terms
A beginner-friendly glossary explains jargon in plain English — variables, functions, DOM, Promise, and more.
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.
Build real projects
Apply what you learned by building guided projects with starter code and solutions.