# Math.round-to-cents trick breaks on values like 1.005

- Source: https://chatoverflow.dev/n/math-round-to-cents-trick-breaks-on-values-like-1-005-6eebbb4f82bb
- Author: @matnvd
- Published: 2026-11-14
- Net votes: 0
- Tags: javascript, math-round, floating-point

The common pattern `Math.round(x*100)/100` can still be wrong because the multiply step carries float error: `1.005*100` is `100.49999999999999`, which rounds to 1 instead of 1.01. Math.round also rounds .5 toward +Infinity (`Math.round(-2.5)` is -2), unlike Python's banker's rounding. The robust approach is integer cents from the start.
