darenw Posted October 5, 2012 Share Posted October 5, 2012 The below keeps returning false with the same values. Why? Code: if($this->Paypal->ipn_data['mc_gross'] != money_format('%i', $package['Package']['price'])) { $this->log('PAYPALIPN: FAILURE! Wrong price: '.$this->Paypal->ipn_data['mc_gross'].' == '.$package['Package']['price'], 'payment'); Error log msg: 2012-10-04 16:48:41 Payment: PAYPALIPN: FAILURE! Wrong price: 0.15 == 0.15 2012-10-04 16:48:41 Payment: PAYPALIPN: End function Quote Link to comment Share on other sites More sharing options...
xyph Posted October 5, 2012 Share Posted October 5, 2012 You're missing the money_format call in your log. Quote Link to comment Share on other sites More sharing options...
darenw Posted October 5, 2012 Author Share Posted October 5, 2012 Even using this I get the same results 0.15 != 0.15 should be equal and not step into the log. if($this->Paypal->ipn_data['mc_gross'] != $package['Package']['price']) { $this->log('PAYPALIPN: FAILURE! Wrong price: '.$this->Paypal->ipn_data['mc_gross'].' == '.$package['Package']['price'], 'payment'); Error log msg: 2012-10-04 16:48:41 Payment: PAYPALIPN: FAILURE! Wrong price: 0.15 == 0.15 2012-10-04 16:48:41 Payment: PAYPALIPN: End function Quote Link to comment Share on other sites More sharing options...
Jessica Posted October 5, 2012 Share Posted October 5, 2012 If they're strings, you may need to trim them. Quote Link to comment Share on other sites More sharing options...
darenw Posted October 5, 2012 Author Share Posted October 5, 2012 Sorry but I am new to this could you please give a example Quote Link to comment Share on other sites More sharing options...
Jessica Posted October 5, 2012 Share Posted October 5, 2012 (edited) http://lmgtfy.com/?q=php+trim Edited October 5, 2012 by Jessica Quote Link to comment Share on other sites More sharing options...
DavidAM Posted October 6, 2012 Share Posted October 6, 2012 And if they are floats, you will run into problems testing for equality. You should use the same formatting function on both sides of the test. That way you will be comparing strings on both sides. After all, the call to money_format() using the %i formatting code is returning 'USD 0.15' NOT 0.15; which is probably what xyph was trying to tell you in his first response. 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.