5. php-floating-point number to integer PHP floating-point number comparison PHP floating-point accuracy php floating-point number format

Source: Internet
Author: User
Tags type null
1. Using forced type conversions

First, PHP supports data types such as the following:

1. Integer    (整数)2. Float      (浮点数)3. String     (字符串)4. Boolean    (布尔值)5. Array      (数组)6. Object     (对象)

There are also two special types: null (empty), resource (Resource).

Note:
1. A variable that is not assigned, has been reset, or is assigned a special value of NULL is a variable of type null.
2. A specific built-in function (such as a database function) returns a variable of type resource.

You can then use a forced type conversion like C, such as


   
    $a=6.66666;$b=(integer)$a;echo$b;

Will output a 6, directly out of the decimal part

2. Use float floor (float value) function

The rounding method takes the whole, returns the next integer not less than value, and the fractional part of value is rounded off. The type returned by floor () is still float, because the range of float values is usually larger than the integer.

floor(4.3);   // 输出4 floor(9.999// 输出9

3. Using the float ceil (float value) function

Returns the next integer not less than value, in which value is entered if there is a fractional part. The type returned by Ceil () is still float, because the range of float values is usually larger than the integer.

ceil(4.3);    // 输出5 ceil(9.999);  // 输出10

4. Use float round (float val [, int precision]) function

Rounds a floating-point number, returning the result of rounding Val based on the specified precision precision (the number of digits after the decimal point). Precision can also be negative or 0 (the default value).

round(3.4);         // 输出3 round(3.5);         // 输出4 round(3.6);         // 输出4 round(3.60);      // 输出4 round(1.955832);  // 输出1.96 round(1241757, -3// 输出1242000 round(5.0452);    // 输出5.04 round(5.0552);    // 输出5.06

'). addclass (' pre-numbering '). Hide (); $ (this). addclass (' has-numbering '). Parent (). append ($numbering); for (i = 1; i <= lines; i++) {$numbering. Append ($ ('
  • '). Text (i)); }; $numbering. FadeIn (1700); }); });

    The above is introduced 5, php-floating point to integer, including the content of PHP, floating point, I hope the PHP tutorial interested in a friend helpful.

  • Related Article

    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.