PHP to take the whole, rounded rounding, up rounding, down to the whole, decimal intercept ____php

Source: Internet
Author: User

php to take the integer function commonly used in four ways:

1. Direct rounding, discard decimals, keep integers: intval ();
2. Rounded rounding: round ();
3. Take the whole up, there are decimals plus 1:ceil ();
4. Take the whole down: floor ().

One, intval-to the variable to the integer form
Intval is automatically converted to 0 if it is a character type.

Intval (3.14159);  3
intval (3.64159);  3
intval (' Ruesin ');//0

Second, rounded: round ()

The parameter 1 is rounded according to the specified precision of parameter 2. Parameter 2 can be a negative number or 0 (the default value).

Round (3.14159);      3
round (3.64159);      4
round (3.64159, 0);   4
Round (3.64159, 2);   3.64
Round (5.64159, 3);   3.642
Round (364159,-2);   364200

Third, to take the whole up, with a decimal number plus 1:ceil ()

Returns the next integer that is not less than value, or the value if there is a decimal part.

This method is often used when we write page classes to calculate the number of pages.

Ceil (3.14159);  4
ceil (3.64159);  4

Four, downward rounding: Floor ()

Returns the next integer not more than value, rounding out the decimal part of value.

Floor (3.14159);    3
floor (3.64159);    3

Reprint please indicate the source: http://blog.csdn.net/churk2012/article/details/51424588

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.