Re: Why do these values not match?

From: Date: Tue, 25 Jun 2002 22:58:22 +0000
Subject: Re: Why do these values not match?
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-20114@lists.php.net to get a copy of this message
Looks like a bug in PHP since the types are both set correctly and appear equal. Doing a cast/recast should never change the "value" and have it suddenly compare okay via the last "!=" operator. Filed report Bug #17984 along with attached script. <?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 ----- Original Message ----- From: "Manuel" <manuel@ochoa-usa.com> To: <php-db@lists.php.net> Sent: Tuesday, June 25, 2002 3:00 PM Subject: [PHP-DB] Why do these values not match? > > The "if" statement is not working here. Does anybody know why? > > $total= 332.06; > $production = 45.11 + 134.38 + 85.35 + 67.22; > > print("Total = $total<br>"); > print("Production = $production<br>"); > > if($total != $production) { > print("Totals do not Match!"); > } > else { > print("Totals are in Balance"); > } > > > > --------------------------------- > Do You Yahoo!? > Sign-up for Video Highlights of 2002 FIFA World Cup

« previous php.db (#20114) next »