Alicia Posted October 18, 2012 Share Posted October 18, 2012 Hi, May I know why my conditional statement doesn't work when comparing with decimal point input? $money = 0.2; if($money<=0) { echo 'no money'; { else { echo 'OK'; } The output after multiple tries by using intval or float , it still show OK when it suppsed to show no money... May i know what I have missed? it seems like the php script cant recognize 0.2 is smaller than 0. please advise Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted October 18, 2012 Share Posted October 18, 2012 0.2 is grater than zero. Perhaps you meant less than 1 Quote Link to comment Share on other sites More sharing options...
ManiacDan Posted October 18, 2012 Share Posted October 18, 2012 Yeah...what's the actual problem here? Quote Link to comment Share on other sites More sharing options...
Jessica Posted October 18, 2012 Share Posted October 18, 2012 0.2 is grater than zero. 0.2 grater than zero? ;D Quote Link to comment Share on other sites More sharing options...
JohnTipperton Posted October 19, 2012 Share Posted October 19, 2012 (edited) Hi, May I know why my conditional statement doesn't work when comparing with decimal point input? $money = 0.2; if($money<=0) { echo 'no money'; { else { echo 'OK'; } The output after multiple tries by using intval or float , it still show OK when it suppsed to show no money... May i know what I have missed? it seems like the php script cant recognize 0.2 is smaller than 0. please advise change your code into $money = 0.2; if($money<=1) { echo 'no money'; } else { echo 'OK'; } 0.2 is greater than zero hope it works Edited October 19, 2012 by JohnTipperton Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted October 19, 2012 Share Posted October 19, 2012 0.2 money isn't the same as no money, though. The OP needs to define what constitutes "no" money. Quote Link to comment Share on other sites More sharing options...
JohnTipperton Posted October 19, 2012 Share Posted October 19, 2012 0.2 money isn't the same as no money, though. The OP needs to define what constitutes "no" money. yea its kinda weird on his conditional statement the $money should be i think 0 to appear no money. Quote Link to comment 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.