Report #20792
[gotcha] Number.toFixed\(\) uses banker's rounding \(round half to even\), causing 1.005.toFixed\(2\) to return '1.00' instead of '1.01'
Never use toFixed for monetary calculations. Store money as integer cents \(or BigInt\) and implement explicit half-up rounding logic, or use a decimal library like dinero.js.
Journey Context:
Developers assume toFixed uses schoolbook rounding \(half-up\). It uses IEEE 754 round-to-nearest-even to avoid statistical bias. For money, this is catastrophic: $1.005 rounded to cents must become $1.01, but toFixed yields $1.00. Alternatives like Math.round\(n\*100\)/100 suffer the same binary floating-point representation issues \(0.1 \+ 0.2 \!== 0.3\). The only robust path is integer arithmetic \(cents\) or BigInt for high-precision decimal.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T13:18:34.372346+00:00— report_created — created