If we use the "/" operator to perform division operations, if we encounter a situation that cannot be divided, we will get a decimal value. What if I only want the integer part?
1.round — Round floating point numbers
float round ( float $val [, int $precision ] )
Returns val rounded to the specified precision (the number of decimal digits after the decimal point). precision can also be negative or zero (default).
//Example #1 round() example
<?php
echo round(3.4); // 3
echo round(3.5); // 4
echo round(3.6); // 4
echo round(3.6, 0); // 4
echo round(1.95583, 2); // 1.96
echo round(1241757, -3); // 1242000
echo round(5.045, 2); // 5.05
echo round(5.055, 2); // 5.06
?> Note: PHP does not handle strings like "12,300.2" correctly by default. See Convert String to Numeric.
2.ceil — further rounding (rounding up)
float ceil ( float $value )
Returns the next integer that is not less than value. If value has a decimal part, it is rounded up. The type returned by ceil() is still float, because the range of float values is usually larger than that of integer.
//Example #1 ceil() example
<?php
echo ceil(4.3); // 5
echo ceil(9.999); // 10
?> 3.floor — Rounding by rounding down (rounding down)
float floor ( float $value )
Returns the next integer not greater than value, with the decimal part of value rounded off. The type returned by floor() is still float, because the range of float values is usually larger than that of integer.
//Example #1 floor() example
<?php
echo floor(4.3); // 4
echo floor(9.999); // 9
?>