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