Which fix removes the bug?
const price = 2.567; const shown = Math.round(price, 2); console.log(shown); // expected 2.57
- Use
Math.round(price * 100) / 100 - Use
Math.floor(price, 2)there instead - Use
Math.round(price) / 100here - Pass the digits as a string:
"2"
Math.round takes one argument and always rounds to an integer; scale up, round, then scale back.
Play Problem Solving ▸