Rounding functions in PHP

Source: Internet
Author: User
Php & nbsp; usually needs to be rounded off when processing floating point numbers. There are three functions in php & nbsp; for this situation: floor function, ceil function, and round function. The combination of floor and ceil functions makes the data processed by php & nbsp; more authentic and reliable. I. First, let's look at the floor function: syntax: floatfloor (

Php? When processing floating point numbers, it is often necessary to rounding. In php? There are three functions that apply to this situation:Floor function, ceil function, and round function.

The floor function and ceil function work together to make php? The processed data is more authentic and reliable.

I. First, let's look at the floor function:

Syntax:

float floor ( float value )

Note:

Returns the next integer not greater than value and rounds the decimal part of value. The return type of floor () is still float, because the float value range is usually larger than that of integer.

Floor ()? Example

 

II. ceil functions:

Syntax:

float ceil ( float value )

Note:

Returns the next integer of no less than value. if the value has a decimal part, it is entered in one place. The type returned by ceil () is still float, because the float value range is usually larger than integer.

Ceil ()? Example:

 

See the differences between the two functions ..

Of course, you need to useRoundFunction.

III. round functions:

Syntax:

float round ( float val [,?int?precision] )

Note:

Returns the result of rounding val by the specified precision (number of digits after decimal point. Precision can also be negative or zero (default ).

Round ()? Example

 

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.