Ceil is a function that returns a value in the ascending order;
Floor is a function used to remove the decimal places to get a value;
Round is a rounding function.
Ceil
Definition and usage:
The ceil () function rounds up to the nearest integer.
Copy codeThe Code is as follows:
Ceil (x );
Note:
Returns the next integer of no less than x. If x has a decimal part, the return value is one digit.
The type returned by ceil () is still float.
Example:
Copy codeThe Code is as follows:
<? Php
Echo ceil (1, 0.60 );
Echo "<br/> ";
Echo ceil (1, 0.40 );
Echo "<br/> ";
Echo ceil (5 );
Echo "<br/> ";
Echo ceil (1, 5.1 );
Echo "<br/> ";
Echo ceil (-5.1 );
Echo "<br/> ";
Echo ceil (-5.9 );
?>
Output:
Copy codeThe Code is as follows:
1
1
5
6
-5
-5
Floor
Definition and usage:
The floor () function rounds down to the nearest integer.
Copy codeThe Code is as follows:
Floor (x );
Note:
Returns the next integer not greater than x and rounds the decimal part of x.
The returned type of floor () is still float.
Example:
Copy codeThe Code is 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 (-1, 5.9 ))
?>
Output:
Copy codeThe Code is as follows:
0
0
5
5
-6
-6
Round
Definition and usage
The round () function rounds a floating point number.
Copy codeThe Code is as follows:
Round (x, prec );
Where
X (optional) specifies the number to be rounded.
Prec (optional) specifies the number of digits after the decimal point.
Note:
Returns the result of rounding x to the specified precision prec (number of digits after decimal point.
Prec can also be a negative number or zero (default ).
Example:
Copy codeThe Code is 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 codeThe Code is as follows:
10
12
1
0
-1
-0