How to format float/decimal in JavaScript

{0 Comments}

In JavaScript when you get result in decimal/float and it contains too much number after decimal. Like 2.34345566, and you want to format this so that you can get result like 2.34 only then you can use following trick or cheat you say.

 Javascript |  copy code |? 
1
var result = Math.round(original*100)/100;

You can change the number of Zeros to get different result. 

Leave a Comment

Your email address will not be published.