1
var value1 = 1.325;
var value2 = 8.925;

console.log(value1.toFixed(2)); // my result: 1.32
console.log(value2.toFixed(2)); // my result: 8.93

value1 should be 1.33 but I am getting 1.32. value2 is getting rounded correct.

EDIT/SOLUTION: This question is not a duplicate. (please see the comments). The only working code for this question is:

function round(value, decimals) {
        return Number(Math.round(value+'e'+decimals)+'e-'+decimals);
}
Mike
  • 3,200
  • 5
  • 22
  • 33

0 Answers0