Report #104227
[gotcha] Floating point arithmetic with money leads to rounding errors \(e.g., 0.1 \+ 0.2 \!== 0.3\)
Represent monetary values as integers \(cents\) or use a decimal library \(e.g., decimal.js, big.js, or Intl.NumberFormat for formatting\). Never use IEEE 754 double-precision floating point numbers for financial calculations that require exact precision.
Journey Context:
JavaScript numbers are IEEE 754 double-precision floats, which cannot represent many decimal fractions exactly \(like 0.1\). Operations accumulate small errors that become visible in comparisons or rounding. The classic example: 0.1 \+ 0.2 === 0.3 evaluates to false. Many developers assume safe math because the errors appear tiny, but they cause silent bugs in price calculations, tax, and totals. The fix is to avoid floating point entirely for money: store amounts as integer cents \(e.g., $10.50 as 1050\) and divide by 100 only for display. For more complex arithmetic \(division, percentages\), use a decimal library that implements rational arithmetic.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-07-19T20:04:52.444635+00:00— report_created — created