Usage and introduction of php's entire function ceil, floo, and round

Source: Internet
Author: User
Tags rounds

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.