Exception parsing for int conversion of intval () in PHP

Source: Internet
Author: User
This article introduces, in PHP using Intval () for int conversion, encountered an abnormal situation, and the solution, for your reference.

Test code for PHP's Intval () function:

 
      
HTML code:

Run Result: float (945) int (944) float (945) int (945)

Explanation: 9.45 This number is what we see, but the inside of the machine is not this, but the 9.44999999999999999. So: 9.449999*100 = 944.9999. Intval the mantissa straight away, so that the intval and floor () functions are similar. This is not noticed before. Nor did I notice that the intval would be rounded down. and 1.00 There is no 1.0099999 such a, so 945*1.00 will appear a float of 945. That intval to transform nature will not appear 944 of the situation. There are some classic test questions, such as: Intval ((0.1+0.7) *10) equals 7 instead of 8. That's the truth.

How about, introduced here, for PHP this intval () function, understand it.

  • 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.