Jump to content

[SOLVED] Comparison between two floating point numbers not working!!!!


robcrozier

Recommended Posts

Hi.

 

Basically what i'm trying to do is compare two floating point numbers in order to see if one is less than or equal to the other, and if so proceed with extra functionality.  If not, an error is displayed.

 

Here's that very simple code that i'm using:

 

if ($var1 <= $var2)
       echo "proceed";
else
      echo "dont proceed";

 

This code works absolutely fine on all floating point numbers (so far) except if both vars are 17.99.  If this is the case the compare does not see the two numbers as equal, it sees var2 as less than var 1!?

 

I've used the is_numeric() function just to make sure that both numbers are being treat as numeric by the script... and they are.  I've also used the htmlentities() function to make sure that no html tags etc are part of the var... and once again it's all fine!?

 

Any suggestions?  It's doing my head in!

 

Thanks

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.