Skip to content
Advertisement

How to truncate (not round) a particular number after decimal point using javascript

input : -81.82637799999999(14 numbers after decimal point)

output :-81.8263779999999(13 numbers after decimal point)

How can I implement this using javascript?

Advertisement

Answer

Well try this. See if it works for you

var x = -81.82637799999999;
x = x.toString(); // convert to string
alert(x.length);
x = x.substring(0, x.length - 1); // cut out last character
alert(x.length);
x = parseFloat(x); // convert it back to float

https://jsfiddle.net/9sngtp3n/1/

Advertisement