Which fix removes the subtle bug?
const total = items.reduce((sum, i) => sum + i.price, 0); const cents = total * 100; save(Math.round(cents));
- Round each price to cents before summing
- Round each price to cents after summing
- Store the total as a fixed-2 string value
- Replace
Math.roundwithMath.floor
Summing binary floats accumulates error; convert to integer cents first and add those.
Play Problem Solving ▸