Tuesday, May 3, 2016

How to format a float in javascript?

 We get just 2 digits after the decimal point
Example

var result = Math.round(original*100)/100;

Example:

var x = 5.0364342423;
alert(x.toFixed(2));
Result: 5.04.

Example:


var x = parseInt(5.0364342423);
alert(x.toFixed(2));
Result: 5.04.

No comments:

Post a Comment