Looking to Build/Redesign a Website or Blog ?

To speak to Rakshit, call +91 968 704 2303

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.

Enter your email address:
Feel free to ask any question. Just leave your comment below and we will answer your comment with in 24 hours.


Leave a Reply

Your email address will not be published.