0.14 does not equal 0.14?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
nutkenz
Forum Contributor
Posts: 155
Joined: Tue Jul 19, 2005 12:25 pm

0.14 does not equal 0.14?

Post 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?
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Please read the paragraph about "Floating point precision" at http://de2.php.net/float
nutkenz
Forum Contributor
Posts: 155
Joined: Tue Jul 19, 2005 12:25 pm

Post by nutkenz »

Ok, thanks, I'll convert them to strings then. That'll be the easiest way out.
Post Reply