JavaScript Precision Bug: `0.1 + 0.2 === 0.30000000000000004` (IEEE 754 Binary64)

Decimal tenths have infinite repeating binary fractions in 64-bit IEEE 754 floats.

Runs locally in browser Free · No login Independently Verified 2026-11-25 v4.1.0
Identifier: JavaScript Precision Bug Platform: JavaScript
Common Root Causes:
  • Decimal tenths have infinite repeating binary fractions in 64-bit IEEE 754 floats.

Interactive Diagnostic Checklist

Verified Solutions:
  1. Store currency in integer minor units (cents/paise) or compare floats within an explicit tolerance.
Safe Diagnostic Command:
Test equality with `Math.abs(a - b) < 1e-12`
Warning: Verify configuration changes in staging or with dry-run flags (e.g. nginx -t) before reloading production services.

Technical Explanation

Decimal tenths have infinite repeating binary fractions in 64-bit IEEE 754 floats. Recommended diagnostic: `Test equality with `Math.abs(a - b) < 1e-12``. Remediation: Store currency in integer minor units (cents/paise) or compare floats within an explicit tolerance.

Worked Examples

  • Run `Test equality with `Math.abs(a - b) < 1e-12`` to verify root cause before applying the remediation.

Limitations & Assumptions

  • Always verify configuration changes in staging or with dry-run flags (e.g. `nginx -t`) before reloading production services.

Source References & Verification

Resource ID: err-js-floating-point-01-plus-02 · Independently verified: 2026-11-25

Related Resources