Reputation: 4927
I have this
Math.round((Math.abs(21600 / 3600))*100)/100
>> 6 # want 6.00
Math.round((Math.abs(21000 / 3600))*100)/100
>> 5.83 # This is right
I need 2 decimals on whole number.
Upvotes: 3
Views: 3406
Reputation: 17080
You can use toFixed() method:
var num = num.toFixed(6);
Now num wil be equal to 6.00
Upvotes: 1
Reputation: 339856
You can use .toFixed()
, but there's no need to manually round the value to the nearest 0.01 first - the .toFixed
function will do that for you.
var str = Math.abs(21600 / 3600).toFixed(2);
Upvotes: 7
Reputation: 236032
Use Number.prototype.toFixed()
MDN.
(Math.round((Math.abs(21600 / 3600))*100)/100).toFixed( 2 );
Upvotes: 2
Reputation: 203379
Try this:
(Math.round((Math.abs(21600 / 3600))*100)/100).toFixed(2)
Upvotes: 1