Jump to content

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


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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.