Javascript floating point precision(Sets the number of decimal points)
Hello Friends,
If you have a problem with floating point precision when you update any number in html using javascript/jquery than here i show you the way how to get number formatted with decimals (set 2 digits after decimal point in float number) from javascript. In PHP, you can simply use number_format() function and pass the parameter as you want for floating point precision(Sets the number of decimal points).
For javascript, you can do the same using toFixed() function. Before using this function do not forgot to convert variable in float number using parseFloat() in javascript. Here is the way how to use toFixed() function to set floating point precision from javascript.
var a = "10";
var float_num = parseFloat(a); // parse as float number
var accurate = float_num.toFixed(2) ); // Will return "10.00"
To know more about programming,JavaScript issues,jQuery,Expression Engine,MYSQL database and Open-source, enter your email address below. We will send you free tutorials.






I am
about 1 year ago
great, toFixed is what I was lookin for
thanks
about 1 year ago
great, toFixed is what I was lookin for
thanks
about 8 months ago
Thanx. Needed that one.
about 4 months ago
Very useful small article. Thank you!