Re: Bug #1259 Updated: Double in a string comparision bug after conve

From: Date: Tue, 23 Mar 1999 23:49:41 +0000
Subject: Re: Bug #1259 Updated: Double in a string comparision bug after conve
References: 1  Groups: php.dev 
Request: Send a blank email to php-dev+get-4744@lists.php.net to get a copy of this message
At 16:25 23/03/99 +0000, Manuel Lemos wrote: >Hello Bug, > >On 23-Mar-99 12:41:11, you wrote: > >>PHP's string conversion routines supress any trailing zeros, very >>much on purpose. If you want to force a certain amount of decimal >>digits, use printf() or sprintf() instead of echo or print. > >Actually that is not the problem. Just compare the strings "1" and "1." >(echo "1"=="1.") and you'll see the bug. It seems PHP converts the >strings >to numbers before comparing even though that's not what's meant because both >sides of the comparision are strings. Again, this is not a bug. PHP does indeed perform a numeric comparison when its operands look like numbers, even if their both originally strings. "1" and "1." are identical as far as the comparison operator is concerned, and so are "1.0", 1, and 1.000. If you want a string comparison, without any numeric 'magic', use strcmp() instead (that is the only reason why strcmp() even exists, otherwise the == operator would have been enough). Zeev -- Zeev Suraski <zeev@zend.com> http://www.zend.com/ For a PGP public key, finger bourbon@netvision.net.il -- PHP Development Mailing List http://www.php.net/ To unsubscribe send an empty message to php-dev-unsubscribe@lists.php.net For help: php-dev-help@lists.php.net

« previous php.dev (#4744) next »