RE: [PHP] IF statement madness
| From: | James E Hicks III | Date: | Fri, 14 Mar 2003 18:43:56 +0000 |
| Subject: | RE: [PHP] IF statement madness | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-139751@lists.php.net to get a copy of this message | ||
Thank you (all who resonded)!!! It makes sense now.
Now I can wait until 5:00pm, quitting time, to go crazy!!
James
-----Original Message-----
From: Johnson, Kirk [mailto:kjohnson@zootweb.com]
Sent: Friday, March 14, 2003 1:23 PM
To: php-general@lists.php.net
Subject: RE: [PHP] IF statement madness
Comparing a float with an integer can have problems. You could try something
like:
if(abs($i - $target) < .00001) {
//then they are essentially equal
}
Kirk
> -----Original Message-----
> From: James E Hicks III [mailto:jameshicks@noland.com]
> Sent: Friday, March 14, 2003 11:22 AM
> To: php-general@lists.php.net
> Subject: [PHP] IF statement madness
>
>
> 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!");
> }
> }
> ?>
>
>
> James E Hicks III
> Noland Company
> 2700 Warwick Blvd
> Newport News, VA 23607
> 757-928-9000 ext 435
> jameshicks@noland.com
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php