var num = 5.3;
// Without arguments, will round to whole numbers:
alert( num.toFixed() ); // Rounded down
num = 7.5;
alert( num.toFixed() ); // Rounded up
var num = 5.785;
alert( num.toFixed(2) ); // 5.79
num = 3.4;
alert( num.toFixed(2) ); // 3.40 - show an extra zero at the end!
Caveat: remember that what you get back is a string. If you re-use variables, make sure to explicitly convert back to integer or float by using parseInt() or parseFloat() methods.
Tip: since toFixed() only affects the "mantissa" (digits on the right of the decimal point), you'll need to write a custom function to pad extra zeros in front of the integer part of numbers.
$num = 5.1;
echo number_format( $num, 2 ) . '<br>'; // 5.10
echo number_format( 3, 2 ) . '<br>'; // 3.00
// European notation, with comma for decimal and space to separate thousands:
echo number_format( 12345, 2, ',', ' ' ); // 12 345,00