At 19:21 14.03.2003, James E Hicks III said:
--------------------[snip]--------------------
>Help save my sanity! What can I do to the IF statement in the following
>code to
>make it print the line that says "By God they are equal in value."? I have
>tried
>the following changes;
>
> 1. using === instead of ==
> 2. placing (float) in front of the $i and $target inside and before
> the IF
>statement.
>
><?
>$start = 215;
>$end = 217;
>$target = 216;
>for ($i=$start; $i<=$end; $i+=.1){
> if ( $i == $target ){
> echo ("<BR>$i - $target, By God, the are equal in value.");
> } else {
> echo ("<BR>$i - $target, Eternal Damnation, they aren't
>equal!");
> }
>}
>?>
--------------------[snip]--------------------
Before the if statement in your loop place this line:
echo "\$i is now: $i<br />";
You'll notice that most probably your $i variable will miss $target by some
hunderths or thousandths, since you're working with it as a float. This is
due to the way fp numbers are stored and calculated (using exponents and
mantissa).
Workaround: don't use floats if you want to hit a certain value at the spot:
<?
$start = 215;
$end = 217;
$target = 216;
for ($i=($start*10); $i<=($end*10); $i++){
if ( $i == ($target*10) ){
echo ("<BR>$i - $target, By God, the are equal in value.");
} else {
echo ("<BR>$i - $target, Eternal Damnation, they aren't
equal!");
}
}
?>
--
>O Ernest E. Vogelsinger
(\) ICQ #13394035
^ http://www.vogelsinger.at/
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php