Page 1 of 1

0.14 does not equal 0.14?

Posted: Mon May 07, 2007 8:37 am
by nutkenz
Here is some code:

Code: Select all

$dbR["current_bid"] = (double) $dbR["current_bid"];
$new_bid = (double) $new_bid;
		
if (@$dbR["current_bid"] != $new_bid)
{
	var_dump($dbR["current_bid"]); var_dump($new_bid);
	echo "Updating ".$dbR["name"].": ".$dbR["keyword"]." (".$dbR["current_bid"]." => ".$new_bid.") ";
}
Here is the output:
float(0.14) float(0.14) Updating name: keyword (0.14 => 0.14) Success!
How come (@$dbR["current_bid"] != $new_bid) evaluates to TRUE? Last time I checked (0.14 DOES NOT EQUAL 0.14) was TRUE... Am I retarded or am I overlooking something?

Posted: Mon May 07, 2007 8:38 am
by volka
Please read the paragraph about "Floating point precision" at http://de2.php.net/float

Posted: Mon May 07, 2007 8:54 am
by nutkenz
Ok, thanks, I'll convert them to strings then. That'll be the easiest way out.