im using this code
$('tr').each(function () {
var td = $(this).children('td').eq(1);
var val = td.html();
if (val > 1000) {
var fixedVal = parseFloat(parseFloat(val).toFixed(3));
td.html(fixedVal / 1000 + " KM");
}
else {
td.html(Math.round(val) + " M");
}
});
and yet iam getting values like
3.5101280000000004 KM
8761.596300000001 KM
the problem is that .toFixed() is not working properly.
You first fix the number and then you divide it by 1000, which creates a new floating point number. Call
toFixedin your.html()line instead.