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.
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.
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);
Use Number.prototype.toFixed()
MDN.
(Math.round((Math.abs(21600 / 3600))*100)/100).toFixed( 2 );