I have a floating point number in JavaScript, like 42.563134634634. I want to display it as a string "42.56", with exactly two decimal places. How do I do that?
Use toFixed
method:
var num = 42.563134634634;
alert(num.toFixed(2));
You could do
var num = 42.563134634634;
var res = num.toFixed(2);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With