I am using this code to get float with only two number after the .
:
var number = 1.9090909090909092;
var newNumber = (number).toFixed(2);
And in newNumber
i get : 1.91
instead of 1.90
. Any idea why it happen?
I am using this code to get float with only two number after the .
:
var number = 1.9090909090909092;
var newNumber = (number).toFixed(2);
And in newNumber
i get : 1.91
instead of 1.90
. Any idea why it happen?
if you want to format a float to any number of digits use this function:
function truncate(num, pos) {
return Math.floor(num*Math.pow(10, pos))/Math.pow(10, pos);
}
where num is the float and pos is the number of digits you want after the decimal.