# Ceil and Floo in PHP and round function _php tutorial

Source: Internet
Author: User
Tags rounds
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 that is used for rounding.

Ceil
Definition and Usage:

The Ceil () function rounds up to the nearest integer.

[PHP]
Ceil (x);

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:

[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);
?>

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:

[PHP]
1
1
5
6
-5
-5

1
1
5
6
-5
-5

Floor
Definition and Usage:

The floor () function rounds down to the nearest integer.

[PHP]
Floor (x);

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:

[PHP]
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))
?>

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:

[PHP]
0
0
5
5
-6
-6

0
0
5
5
-6
-6
Round
Definition and usage

The round () function rounds a floating-point number.

[PHP]
Round (X,PREC);

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:

[PHP]
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);
?>

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:

[PHP]
10
12
1
0
-1
-0

http://www.bkjia.com/PHPjc/477158.html www.bkjia.com true http://www.bkjia.com/PHPjc/477158.html techarticle A ceil is a function that gets a value upward, and the floor is a function that gets a value out of the decimal place; Round is a function that is used for rounding. Ceil definition and Usage: ceil () function up ...

• Related Keywords:
Related Article

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.