Bug #17984 Updated: comparison of float values does not always work.
| From: | derick@php.net | Date: | Wed, 26 Jun 2002 05:23:28 +0000 |
| Subject: | Bug #17984 Updated: comparison of float values does not always work. | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-12105@lists.php.net to get a copy of this message | ||
ID: 17984
Updated by: derick@php.net
Reported By: szii@sziisoft.com
-Status: Open
+Status: Bogus
Bug Type: Unknown/Other Function
Operating System: Linux Mandrake
PHP Version: 4.2.1
New Comment:
Sorry, but the bug system is not the appropriate forum for asking
support questions. Your problem does not imply a bug in PHP itself.
For a list of more appropriate places to ask for help using PHP,
please visit http://www.php.net/support.php
Thank you for your interest in PHP.
http://www.php.net/manual/en/language.types.float.php
Previous Comments:
------------------------------------------------------------------------
[2002-06-25 18:53:42] szii@sziisoft.com
Comparison of float values does not always work.
./configure --with-mysql=/usr/local/mysql --with-xml
--with-apache=../../apache/apache_1.3.26/
Test code follows:
<?php
$a = 332.06;
$b = 45.11 + 134.38 + 85.35 + 67.22;
echo "output\n";
var_dump($a);
var_dump($b);
print("Total = $a\n");
print("Production = $b\n");
if($a != $b)
{
print("Totals do not Match!\n");
}
else {
print("Totals are in Balance\n");
}
if($a !== $b)
{
print("Totals do not Match!\n");
}
else {
print("Totals are in Balance\n");
}
if($a <> $b)
{
print("Totals do not Match!\n");
}
else {
print("Totals are in Balance\n");
}
if($a > $b)
{
print("a is greater!\n");
}
else {
print("b is greater!\n");
}
settype($a,"string");
settype($b,"string");
if ($a != $b)
echo "String compare failed!\n\n";
settype($a,"float");
settype($b,"float");
if ($a != $b)
echo "recast to float compare failed!\n\n";
echo "end output\n";
?>
-----------------------------
output
float(332.06)
float(332.06)
Total = 332.06
Production = 332.06
Totals do not Match!
Totals do not Match!
Totals do not Match!
b is greater!
end output
------------------------------
Summary:
float compare fails (!=)
float compare fails (<>)
float compare fails (!==)
"b" is somehow greater than "a"
cast to string, compare okay.
recast to float, compare okay.
-Mike
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=17984&edit=1