robcrozier Posted May 19, 2008 Share Posted May 19, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/106294-solved-comparison-between-two-floating-point-numbers-not-working/ Share on other sites More sharing options...
robcrozier Posted May 19, 2008 Author Share Posted May 19, 2008 Solved it guys! it appears that some blank spaces were making their way into the var. Using the trim() function removed these and now the comparison works fine! Quote Link to comment https://forums.phpfreaks.com/topic/106294-solved-comparison-between-two-floating-point-numbers-not-working/#findComment-544744 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.