php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #54458 Comparison with intval()
Submitted: 2011-04-03 17:31 UTC Modified: 2011-04-03 20:49 UTC
From: cs dot luizeduardo at hotmail dot com Assigned:
Status: Not a bug Package: Variables related
PHP Version: 5.3SVN-2011-04-03 (SVN) OS: Windows
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: cs dot luizeduardo at hotmail dot com
New email:
PHP Version: OS:

 

 [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

Patches

numeric-test.txt (last revision 2011-04-03 15:36 UTC by cs dot luizeduardo at hotmail dot com)

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-04-03 20:49 UTC] cataphract@php.net
-Status: Open +Status: Bogus
 [2011-04-03 20:49 UTC] cataphract@php.net
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.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Thu Jul 03 13:01:33 2025 UTC