| Handle decimal value in JavaScript?
Below different example help you to understand and handle decimal value with some specific number of decimal points:-
(1)Value upto 2 decimal points
var num = 1.42482;
var num2 = 1;
var fnum = Math.floor(num).toFixed(2);
var fnum2 = Math.floor(num2).toFixed(2);
alert(fnum);
alert(fnum2)
Output of both is : 1.00
(2)Value upto 3 decimal point
var num=5.56789;
var n=num.toFixed(3);
Output of above is :5.568
(3)Handle value for decimal
var num = 16.449;
parseFloat((Math.round(num * 100) / 100).toFixed(2));
output of above is : 16.45 | | |