Fix IEEE-754 floating-point precision drift, negative checkout totals, and unclamped discount percentages.
An AI-generated cart calculator occasionally returns negative totals or floating-point artifacts like 99.99999999999999 when stacking a percentage discount with a flat coupon. Fix calculateTotal(items, percentOff, flatOff).
0.1 + 0.2 === 0.30000000000000004), percentOff has no [0, 100] bounds check, and subtracting flatOff isn't floored with Math.max(0, ...).percentOff into 0..100, compute in integer cents (or round via Math.round((amount + Number.EPSILON) * 100) / 100), and clamp the final total with Math.max(0, total).Ready to run test suite
Edit the code above and press Cmd/Ctrl + Enter or click Run Tests.