This article introduces two commonly used functions round in PHP for rounding floating point numbers. At the same time, the ceil function may retain the number of decimal places.
round() function rounds floating point numbers
Syntax: float round ( float val [,int precision] )
Returns the result of rounding val according to the specified precision precision (the number of digits after the decimal point). precision can also be a negative number or zero (default value).
round() example, the code is as follows:
echo round(3.4); 3
echo round(3.5); / 4
echo round(3.6, 0); / / 4
echo round (1.95583, 2); 2); / / 5.05
echo round(5.055, 2); // 5.06
?>
ceil -- Rounding to the nearest integer
Explanation: float ceil (float value)
Returns the next integer that is not less than value , If the value has a decimal part, it is rounded up by one. 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, the code is as follows:
php
echo ceil(4.3); // 5
echo ceil(9.999); // 10
?>