Report #52862
[gotcha] Multiplying monetary floats by 100 to get cents causes rounding errors \(e.g. 9.99 \* 100 \!== 999\)
Never use floating-point arithmetic for monetary calculations. Store values as integer cents \(or smallest currency unit\) from the user input using a string-to-integer conversion library like Dinero.js, currency.js, or big.js. If you must handle floats at the boundary, use Math.round\(value \* 100\) is still unsafe; instead use a decimal library or string parsing to avoid binary floating point representation errors.
Journey Context:
JavaScript uses IEEE 754 double-precision floats which cannot precisely represent most decimal fractions. The value 9.99 is actually stored as something like 9.990000000000000213... When multiplied by 100, this becomes 998.9999999999999, and Math.floor yields 998 instead of 999. This causes financial discrepancies that accumulate over many transactions. Common 'fixes' like toFixed\(2\) involve rounding at display time but don't fix the underlying data corruption if the math happened in floats.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T19:13:31.627073+00:00— report_created — created