Why does JavaScript print 0.30000000000000004 for 0.1 + 0.2? A Number behaves as an IEEE 754-2019 double-precision, 64-bit floating-point value. Decimal fractions such as 0.1 repeat in binary, so their stored values are approximations before the addition even begins. section 3.1 section 3.5
The 64 bits have three jobs: one bit records the sign, 11 encode an exponent with a bias of 1023, and 52 store significand bits. For the ordinary values illustrated here, an implicit leading 1 supplies another bit of precision. The exponent scales the significand by a power of two; it does not make decimal fractions exact. section 3.1.1
Figure 3.2 The “double-precision” floating point layout divides the 64 available bits into distinct components, including a sign-bit, eleven exponent bits, and 52 bits for the significand.

Locate the sign, exponent, and significand fields before following a value through arithmetic. section 3.1.1
To add 0.1 and 0.2, first align their exponents, then add their binary significands and round the result back to the available precision. The rounded result differs from the stored approximation of 0.3. This is a representation effect, not a JavaScript-specific arithmetic exception. section 3.1.1 section 3.5
Table 3.3 Representing 0.1 and 0.2 as floating-point numbers
|
Value
|
Sign
|
Exponent
|
Significand
|
|
0.1
|
0
|
01111111011
|
1.1001100110011001100110011001100110011001100110011010
|
|
0.2
|
0
|
01111111100
|
1.1001100110011001100110011001100110011001100110011010
|
Compare the encoded exponents and repeating significand patterns of 0.1 and 0.2. section 3.1.1
Two practical boundaries follow from the finite significand:
- Floating-point precision is about 53 binary digits, not a fixed number of decimal places. The largest safe integer is 2^53 − 1; above it, not every integer has a distinct exact representation. section 3.5
- For results expected to be close rather than identical, compare their difference against a tolerance appropriate to their scale. Number.EPSILON can help construct one; it is not a universal tolerance for every magnitude. section 3.1.1
The language specifies Number behavior, not that every arithmetic operation must physically process a full floating-point value. V8 can keep small integers in an optimized SMI representation; changing numeric types in arrays or loops can lose that optimization. Treat the 64-bit format as the behavioral contract, and the runtime representation as an implementation choice. section 3.4 section 3.5







