|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2008-11-10 20:13 UTC] jani@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Oct 27 02:00:01 2025 UTC |
Description: ------------ I've been setting up our system to receive payments via Paypal. Paypal talks via IPN to a URL that I specify. In my code I have logic to verify the transaction. On one line I ran into the problem of addition when verifying transaction amounts. I have tried this test on Win32 running PHP 5.2.3 (Basic AppServ install) and on our live linux environment PHP 5.2.6 with both showing the same results. Reproduce code: --------------- $SubTotal = "67.43"; $Tax = "3.37"; $Amount = $SubTotal + $Tax; "<div>".var_dump($Amount)."</div>"; $Array = array("mc_gross" => "70.80"); echo ($Amount == $Array['mc_gross']) ? $Array['mc_gross'].' is equal to '.$Amount : 'These values are not equal. '.$Array['mc_gross']." is not equal to ".$Amount; echo '<br /><br />Second Test<br /><br />'; $Amount = 70.8; "<div>".var_dump($Amount)."</div>"; echo ($Amount == $Array['mc_gross']) ? $Array['mc_gross'].' is equal to '.$Amount : 'These values are not equal. '.$Array['mc_gross']." is not equal to ".$Amount; Expected result: ---------------- The variable mc_gross, a string with a string value "70.80" should equal the variable $Amount with the float value of 70.8 Actual result: -------------- The first test adds the two variables ($Subtotal and $Tax) together into the variable $Amount. Using var_dump php tells us that $Amount is a float with the value 70.8 When comparing that variable to the one supplied by Paypal (mc_gross) php says that the values are not equal to each other. If you redeclare the variable $Amount and with the value 70.8 and try again, php says the values are equal. var_dump confirms the variable types and value.