Floating point rounding

As toFixed(2) will not return the correct point value in some cases
let num = 3.005;
n = num.toFixed(2);
Result: 3.00
But actual value of result is 3.01
To correct that use the below code.
var roundOff = Math.round((figureToRound* 100 ).toFixed(2))/100;
roundOff = Math.round((3.005* 100 ).toFixed(2))/100;
Result: 3.01

Leave a comment

Your email address will not be published. Required fields are marked *