Round numbers in PHP

Round numbers in PHP

Some handy code I regularly use

[cc lang=”php” escaped=”true” width=”90%” theme=”default” line_numbers=”on”]
echo round(10.5); // Round the number, this example would echo 11.
echo ‘
‘;
echo floor(10.5); // Round down, this would echo 10.
echo ‘
‘;
echo ceil(10.3); // Round up, this would be 11.

//the
echo sprintf(‘%02d’, $minutes);

//Format a number
$english_format_number = number_format($hours, 0, ‘.’, ”);

// All together
echo ‘H:M ‘. $english_format_number ;
echo’:’;
echo sprintf(‘%02d’, $minutes);