I have a problem with two variables, apparently containing equal and identical values, evaluating TRUE when compared with the != operator.
The simple situation is this:
$a is pulled from mysql database A. (where it is a FLOAT column)
$b is the sum of three items pulled from mysql database B.
(where all three are DECIMAL(10,2) columns)
Then a test is performed:
if ($a != $b)
{
// output reporting that the two entries are inconsistent
}
Now, both databases have 600+ rows. All of them have matching values (I have checked... the values are consistent. However, ONE of the rows - only one - is generating the output line. I've put in tons of debugging lines, tested variable types with is_numeric, etc., and only for this one entry does anything go wrong.
I'll start without posting the whole shebang of how the numbers are calculated, etc. But here's a bit of debugging code and it's output. In the example below, $Subtotal is $a as described above. $TotalExpected is $b as described above, and $BookNum is a key/row identifier common to both databases.
If I run this line for the entire set of data:
echo("$BookNum $TotalExpected $Subtotal "
.(is_numeric($TotalExpected)?"TRUE":"FALSE")
." "
.(is_numeric($Subtotal)?"TRUE":"FALSE")
." "
.(($TotalExpected==$Subtotal)?"TRUE":"FALSE")
."<br />");
I get this output (section from the middle of 600+) rows:
... snip ...
SB06A-013 6151.2 6151.2 TRUE TRUE TRUE
SB06A-014 6151.2 6151.2 TRUE TRUE TRUE
SB06A-015 6151.2 6151.2 TRUE TRUE TRUE
SB06A-016 6151.2 6151.2 TRUE TRUE TRUE
SB06A-017 6151.2 6151.2 TRUE TRUE TRUE
SB06A-018 6990 6990 TRUE TRUE TRUE
SB06A-019 6990 6990 TRUE TRUE TRUE
SB06B-001 7823 7823 TRUE TRUE FALSE
SB06B-002 6429.3 6429.3 TRUE TRUE TRUE
SB06B-003 6503.2 6503.2 TRUE TRUE TRUE
SB06B-004 6503.2 6503.2 TRUE TRUE TRUE
SB06B-005 6503.2 6503.2 TRUE TRUE TRUE
SB06B-006 6503.2 6503.2 TRUE TRUE TRUE
SB06B-007 6503.2 6503.2 TRUE TRUE TRUE
... snip ...
Note that SB06A-001 reports the inequality to be FALSE, but that the numbers output in string interpolation are the same, and is_numeric() returns true for both of them. All other entries in these databases report TRUE.
In a separate program I've compared all permutations of the four variables
$a=7823
$b="7823"
$c=7823.00
and all those variables resolve TRUE when compared with ==. Yet, my two variables print the same and are both numeric but fail ==. Only in that one case. Bizarre.
So, I'm at a loss! Any thoughts about what I should check next would be greatly appreciated. I can post more of the actual code if necessary. Thanks!