Re: problem with intval and !=
| From: | Cesar Cordovez | Date: | Thu, 23 Oct 2003 14:57:29 +0000 |
| Subject: | Re: problem with intval and != | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-167294@lists.php.net to get a copy of this message | ||
The other purpose of this procedure is if the user types "12asdasd" into $value, $number will be assigned "12" so $value and $number are not the same, meaning $value is not a number. Which is correct, but the procedure is not working correctly in PHP when it should. (It works in c, c++, fortran and, believe it or not HyperCard!!!)
Cesar.
Cesar Cordovez wrote:
Curt: My fault! You are right, but thats not what I want. $value comes from a form filled by a user. I want $value to be an integer. Not a float. So if the user types "12.3" the system has to send an error msg. Therefore the procedure. By-the-way, Im using PHP 4.3.3 (on windows XP profesional. Don't say a thing!!! I rather work on my mac!) =) Cesar Curt Zirzow wrote:* 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.3I'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) {correct. If you use the floatval() it will echo "Good". Curtecho "Bad";} else {echo "Good"; // echoes Good!!!!!!} The previous should be echoing "Bad". (I think!)