Ceil, floo, and round functions in php

Source: Internet
Author: User
Tags rounds
Ceil is a function for getting a value from the up position; floor is a function for rounding out the decimal places to get a value; round is a function for rounding out. Ceil definition and usage: the ceil () function rounds up to the nearest integer. [Php] ceil (x); Description: return the next integer not less than x. If x has a decimal part, the return value is one. Ceil (

Ceil is a function for getting a value from the up position; floor is a function for rounding out the decimal places to get a value; round is a function for rounding out. Ceil definition and usage: the ceil () function rounds up to the nearest integer. [Php] ceil (x); Description: return the next integer not less than x. If x has a decimal part, the return value is one. Ceil (

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.

[Php]

Ceil (x );

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:

[Php]

Echo ceil (1, 0.60 );

Echo"

Echo ceil (1, 0.40 );

Echo"

Echo ceil (5 );

Echo"

Echo ceil (1, 5.1 );

Echo"

Echo ceil (-5.1 );

Echo"

Echo ceil (-5.9 );

?>

Echo ceil (1, 0.60 );

Echo"

Echo ceil (1, 0.40 );

Echo"

Echo ceil (5 );

Echo"

Echo ceil (1, 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 );

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:

[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 (-1, 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 (-1, 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 );

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:

[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

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.