Report #103676
[gotcha] Number.prototype.toFixed rounding is not symmetric and can produce unexpected results due to binary floating-point
For financial or precise rounding, avoid toFixed. Instead, use a library like decimal.js, or implement rounding with Math.round after scaling \(e.g., Math.round\(1.005 \* 100\) / 100\). Note that even scaling can fail for edge cases \(e.g., 1.005 \* 100 = 100.49999999999999\).
Journey Context:
In IEEE 754, 1.005 is stored as 1.0049999999999999, so toFixed\(2\) returns '1.00' instead of the expected '1.01'. This is not a bug in toFixed itself—it faithfully rounds the exact binary representation—but it surprises developers used to decimal rounding. The common workaround of scaling by 100 and using Math.round also fails for numbers like 1.005. Only a decimal arithmetic library provides reliable rounding.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-07-12T20:03:23.525715+00:00— report_created — created