Solve the phpceil integer problem.

Source: Internet
Author: User
'Var _ dump (ceil (2.2*100) 100); var_dump (ceil (strval (2.2*100) 100 ); 'The output result is float2.21float2.2. Why are the values of the two situations different? Solution. 'Var _ dump (ceil (2.2*100)/100 );
Var_dump (ceil (strval (2.2*100)/100 );'

The output results are as follows:
Float 2.21
Float 2.2
Why are the values of these two cases different? Solution.

Reply content:

'Var _ dump (ceil (2.2*100)/100 );
Var_dump (ceil (strval (2.2*100)/100 );'

The output results are as follows:
Float 2.21
Float 2.2
Why are the values of these two cases different? Solution.

The answer you can see in a certain way. Although still do not understand the underlying principles.

Floating Point decimal point
Many common decimal places are not limited decimal places in binary, and finite digits cannot be accurately recorded.
So what you think is 2.20
Echo sprintf ('% 10.30f', 2.20*100 );
Time
What you will see is:
220.000000000000028421709430404007

Maybe this is related to ceil. It is a floating point operation problem.

In combination with the @ jsuking experiment, it is easy to understand that the 1st answer is 2.21, because it isCeil (220.000000000000028421709430404007).

However, when there are 2nd, it is estimated that strval (2.2*100) automatically gets a small precision,Ceil (220.0000000000000)The total number is 220.

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.