Jump to content

Number Comparison Trouble


darenw

Recommended Posts

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.