"Greater than" issue
Posted: Fri May 21, 2004 9:04 am
I've been using PHP for 3 years now and haven't ever posted, but I'm stumped on this one and need some help.
I've got a big loop going through an array. What I'm seeing is that one 1 certain set of values, an expression like x>y evaluates to true even though x = y. Completely wrong! Here's my code snippet.
So, what it's supposed to do is that if x > the min and x <= the max, increase num.
This code works great except in one case where $x = 2.982 and $ymin = 2.982. In that case, this equation evaluates to true and $num is increased.
So, I thought maybe had an issue with the logical && (even though it's so simple code), so I added a statement directly above the ymin,ymax code:
This evaluates to true only when both of those numbers = 2.982. What am I missing? 2.982 is not greater than itself, is it?
I've got a big loop going through an array. What I'm seeing is that one 1 certain set of values, an expression like x>y evaluates to true even though x = y. Completely wrong! Here's my code snippet.
Code: Select all
for ($j=0;$j<$totalcount;$j++) {
if (($x[$j] > $ymin) && ($x[$j] <= $ymax)) {
$num++;
}
}This code works great except in one case where $x = 2.982 and $ymin = 2.982. In that case, this equation evaluates to true and $num is increased.
So, I thought maybe had an issue with the logical && (even though it's so simple code), so I added a statement directly above the ymin,ymax code:
Code: Select all
if ($x[$j] > $ymin) {
echo "hello";
}