|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2011-04-03 17:31 UTC] cs dot luizeduardo at hotmail dot com
Description:
------------
comparisons with intval() function with real values between 1 and 2 (like 1.2 1.3
etc).
Every return any fail;
Test script:
---------------
$numero = "1.1";
if (intval($numero * 100) == $numero * 100)
{
echo intval($numero * 100) . ":" . $numero * 100 . "<br/>";
echo "Number OK!";
} else {
echo intval($numero * 100) . ":" . $numero * 100 . "<br/>"; //Return 110:110 (same) but the comparison has fail
echo "The number shoud contains 2 decimal places";
}
Expected result:
----------------
110:110
Number OK!
OBS: With the variable with the 2.1 for example, the return result are the
expected.
Actual result:
--------------
110:110
The number shoud contains 2 decimal places
Patchesnumeric-test.txt (last revision 2011-04-03 15:36 UTC by cs dot luizeduardo at hotmail dot com)Pull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Nov 02 03:00:01 2025 UTC |
In[1]:= SetAccuracy[(1.1*100.), Infinity] - 110 // N[#, 20] & Out[1]= 1.4210854715202003717*10^-14 In[2]:= SetAccuracy[110., Infinity] - 110 // N[#, 20] & Out[2]= 0 110 is exactly representable in an IEEE 754 double precision number; 1.1 is not. When 1.1 is multiplied by 100, the error in the representation of 1.1 is propagated and we don't end up with the exact 110. In PHP: echo sprintf("%.20f %.20f\n", 110., 1.1 * 100); 110.00000000000000000000 110.00000000000001421085 Closing as bogus.