Re: problem with intval and !=

From: Date: Thu, 23 Oct 2003 14:33:07 +0000
Subject: Re: problem with intval and !=
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-167283@lists.php.net to get a copy of this message
* Thus wrote Cesar Cordovez (phpguru@cesamo.com): > Can somebody explain me why is this happening? > > $value = "12.3"; > $number = intval($value); > > echo "Number: $number, Value: $value<br>"; > // echoes: Number: 12, Value: 12.3 I'm guessing you wondering why the .3 is removed. Thats because 12.3 isn't an integer but a float. $number = floatval($value); > > if ($number != $value) { > echo "Bad"; > } else { > echo "Good"; // echoes Good!!!!!! > } > > > The previous should be echoing "Bad". (I think!) correct. If you use the floatval() it will echo "Good". Curt -- "My PHP key is worn out" PHP List stats since 1997: http://zirzow.dyndns.org/html/mlists/

« previous php.general (#167283) next »