$ ./guess_the_languageProblem Solving — fix the bug
Problem Solving — fix the bug · easy · #225

Which fix removes the bug?

const price = 2.567;
const shown = Math.round(price, 2);
console.log(shown); // expected 2.57
  1. Use Math.round(price * 100) / 100
  2. Use Math.floor(price, 2) there instead
  3. Use Math.round(price) / 100 here
  4. 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 ▸