ID: 44898
User updated by: zero at infernotechnologies dot net
Reported By: zero at infernotechnologies dot net
Status: Open
Bug Type: Math related
Operating System: CentOS Enterprise 4.5 x86_64
PHP Version: 5.2.6
New Comment:
It seems adding a single line fixes the issue:
Line to add:
---------------------
$result = floatval($result . ' ');
Working version:
---------------------
$value1 = '1';
$value2 = '0.9';
$value3 = 0.1;
$result = floatval(floatval($value1) - floatval($value2));
$result = floatval($result . ' ');
if ($result >= $value3)
{
echo 'Working as intended';
}
else
{
echo "$result IS NOT >= $value3<br />";
var_dump($result, $value3);
}
Previous Comments:
------------------------------------------------------------------------
[2008-05-02 20:43:47] zero at infernotechnologies dot net
Description:
------------
floatval() two seperate strings to return a result, try result against
exact same number (via >=) and condition returns false.
Reproduce code:
---------------
$value1 = '1';
$value2 = '0.9';
$value3 = 0.1;
$result = floatval(floatval($value1) - floatval($value2));
if ($result >= $value3)
{
echo 'Working as intended';
}
else
{
echo "$result IS NOT >= $value3<br />";
var_dump($result, $value3);
}
Expected result:
----------------
Working as intended
Actual result:
--------------
0.1 IS NOT >= 0.1
float(0.1) float(0.1)
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=44898&edit=1