What is the result of adding 0.1 and 0.2 in JavaScript?
Answer
0.30000000000000004
Answer
0.30000000000000004
In JavaScript, adding 0.1 and 0.2 produces 0.30000000000000004. The surprising result comes from the way JavaScript stores ordinary numbers: the IEEE 754 binary64, or double-precision, floating-point format.
The decimal fractions 0.1 and 0.2 have no finite exact representation in base 2. JavaScript therefore stores the nearest representable binary values. When those approximations are added, the rounded result is slightly greater than the mathematical value 0.3, and converting it back to decimal exposes the extra digits.
This is not a JavaScript-only defect. Many languages using IEEE 754 floating-point numbers show similar behavior, although their formatting rules may display the result differently. JavaScript’s `Number` type uses double precision for both integers and fractional values, which makes this issue common in calculations involving money or measurements.
For exact decimal arithmetic, developers commonly store monetary amounts as integer units such as cents, compare values within a tolerance, or use a decimal-arithmetic library. The `toFixed()` method can format a value for display, but it does not change the underlying floating-point representation.
Source: Wikipedia · fact-checked Aug. 2026