I want to round off a number in php, but if there is a 0 at the end of the number, then it does not show two digits at the end of the number.
For example, if the number is 13.50, then output is 13.5
and if the output is 13.59, then it shows the same output as 13.59
Is there any way i can show the output to 13.50 ?
The code I am using is
<?php
$a=4.50;
$b=3;
$d=$a*$b;
echo $c=round($d,2);
?>
I suppose you could use the
number_format()function to format your numbers with two decimals.For example, the following two lines of code :
would get you the following output :
Of couse, instead of passing arbitrary float values to
number_format(), you’ll have to pass it what’s returned byround().