Round Decimals

[Solved] Round Decimals | Perl - Code Explorer | yomemimo.com
Question : Round Decimal

Answered by : fazeel-ahmed

Number((2.935).toFixed(2)) //2.94
Number((12.349345).toFixed(4)) //12.2493
Number((2.5398).toFixed(3)) //2.540
Number((1.005).toFixed(2)) //outputs 1 instead of 1.01
Number((1.555).toFixed(2)) //outputs 1.55 instead of 1.56

Source : https://livecodestream.dev/post/awesome-javascript-one-liners-to-look-like-a-pro/ | Last Update : Fri, 14 Jan 22

Question : Round to 2 decimal places

Answered by : keenan-du-plessis

function roundToTwo(num) { return +(Math.round(num + "e+2") + "e-2");
}
console.log(roundToTwo(2.005));

Source : https://www.delftstack.com/howto/javascript/javascript-round-to-2-decimal-places/ | Last Update : Thu, 14 Apr 22

Question : round to 2 decimal places

Answered by : aditya-raj-ed21b006

a = 2.154327
a_2_decimal = "{:.2f}".format(a)

Source : https://pythonguides.com/python-print-2-decimal-places/ | Last Update : Fri, 01 Jul 22

Answers related to round decimals

Code Explorer Popular Question For Perl