Ceil is a function of rounding up to get a value;
Floor is a function of dropping a decimal bit to get a value;
Round is a function for rounding.
Ceil
Definition and Usage:
The Ceil () function is rounded up to the nearest integer.
Copy Code code as follows:
Description:
Returns the next integer not less than x, if X has a decimal part.
The type returned by Ceil () is still float.
Example:
Copy Code code as follows:
<?php
echo ceil (0.60);
echo "<br/>";
Echo ceil (0.40);
echo "<br/>";
Echo ceil (5);
echo "<br/>";
echo ceil (5.1);
echo "<br/>";
Echo ceil (-5.1);
echo "<br/>";
Echo ceil (-5.9);
?>
output:
Copy Code code as follows:
Floor
Definition and Usage:
The floor () function is rounded down to the nearest integer.
Copy Code code as follows:
Description:
Returns the next integer less than x, rounding out the decimal part of X.
The type returned by floor () is still float.
Example:
Copy Code code as follows:
<?php
Echo (Floor (0.60));
echo "<br/>";
Echo (Floor (0.40));
echo "<br/>";
Echo (Floor (5));
echo "<br/>";
echo "<br/>";
Echo (Floor (5.1));
echo "<br/>";
Echo (Floor (-5.1));
echo "<br/>";
Echo (Floor (-5.9))
?>
output:
Copy Code code as follows:
Round
Definitions and usage
The round () function rounds the floating-point numbers.
Copy Code code as follows:
which
X (optional) Specify the number to round.
PREC (optional) Specify the number of digits after the decimal point.
Description
Returns the result of rounding x according to the specified precision Prec (number of digits after the decimal point).
Prec can also be negative or 0 (the default value).
Example:
Copy Code code as follows:
<?php
Echo round (12.345,-1);
echo "<br/>";
Echo round (12.345);
echo "<br/>";
Echo round (0.5);
echo "<br/>";
Echo round (0.4);
echo "<br/>";
Echo Round (-0.5);
echo "<br/>";
Echo round (-0.4);
?>
output:
Copy Code code as follows: