- Home
- /
- Tutorials
- /
- JavaScript Tutorial
- /
- JavaScript Number Precision
JavaScript Numbers & Math
JavaScript Number Precision
Decimal arithmetic in JavaScript is not always exact, which is why 0.1 plus 0.2 is not 0.3.
This is not a JavaScript bug; it affects almost every language.
Numbers are stored in binary, and some decimals cannot be written exactly in binary.
Example
Example
javascript
console.log(0.1 + 0.2);
console.log(0.1 + 0.2 === 0.3);The output is 0.30000000000000004 then false.
The tiny error is real and it matters.
Why It Happens
Numbers are stored as binary fractions.
