The usage and introduction of Ceil,floo,round function of PHP _php tutorial

Source: Internet
Author: User
A ceil is a function that gets a value upward;
Floor is the function of rounding out the decimal place to get a value;
Round is a function for rounding.

Ceil
Definition and Usage:
The Ceil () function rounds up to the nearest integer.
Copy the Code code as follows:
Ceil (x);

Description
Returns the next integer not less than x, or x if there are fractional parts.
The type returned by Ceil () is still float.

Example:
copy code code as follows:
!--? php echo ceil (0.60);
echo "
";
Echo ceil (0.40);
echo "
";
Echo ceil (5);
echo "
";
echo ceil (5.1);
echo "
";
Echo ceil (-5.1);
echo "
";
Echo ceil (-5.9);
?

output:
copy Code The code is as follows:
1
1
5
6
-5
-5

floor
Definition and usage:
floor () The function is rounded down to the nearest integer.
copy code code is as follows:
floor (x);

Description:
Returns the next integer not less than x, and the fractional part of X is rounded off. The type returned by
Floor () is still float.

Example:
Copy the Code code as follows:
Echo (Floor (0.60));
echo "
";
Echo (Floor (0.40));
echo "
";
Echo (Floor (5));
echo "
";
echo "
";
Echo (Floor (5.1));
echo "
";
Echo (Floor (-5.1));
echo "
";
Echo (Floor (-5.9))
?>

Output:
Copy the Code code as follows:
0
0
5
5
-6
-6

Round
Definition and usage
The round () function rounds a floating-point number.
Copy the Code code as follows:
Round (X,PREC);

which
X (optional) specifies the number to round.
PREC (optional) specifies the number of digits after the decimal point.

Description
Returns the result of rounding x according to the specified precision Prec (the number of digits after the decimal point).
Prec can also be negative or 0 (the default value).

Example:
Copy the Code code as follows:
Echo round (12.345,-1);
echo "
";
Echo round (12.345);
echo "
";
Echo round (0.5);
echo "
";
Echo round (0.4);
echo "
";
Echo Round (-0.5);
echo "
";
Echo round (-0.4);
?>

Output:
Copy the Code code as follows:
10
12
1
0
-1
-0

http://www.bkjia.com/PHPjc/313677.html www.bkjia.com true http://www.bkjia.com/PHPjc/313677.html techarticle A ceil is a function that is rounded up to get a value; the floor is a function that gets a value out of the decimal place, and round is a function that is used to round up ceil definition and usage: the Ceil () function goes up ...

  • 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.