note 7707 modified in intval by zak
| From: | zak@php.net | Date: | Sun, 19 Nov 2000 04:41:31 +0000 |
| Subject: | note 7707 modified in intval by zak | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-7884@lists.php.net to get a copy of this message | ||
intval converts doubles to integers by truncating the fractional component of the number.
When dealing with some values, this can give odd results. Consider the following:
print intval ((0.1 + 0.7) * 10);
This will most likely print out 7, instead of the expected value of 8.
For more information, see the section on floating point numbers in the PHP manual
(http://www.php.net/manual/language.types.double.php)
Also note that if you try to convert a string to an integer, the result is often 0.
However, if the leftmost character of a string looks like a valid numeric value, then PHP will keep
reading the string until a character that is not valid in a number is encountered.
For example:
"101 Dalmations" will convert to 101
"$1,000,000" will convert to 0 (the 1st character is not a valid start for a number
"80,000 leagues ..." will convert to 80
"1.4e98 microLenats were generated when..." will convert to 1.4e98
Also note that only decimal base numbers are recognized in strings.
"099" will convert to 99, while "0x99" will convert to 0.
http://www.php.net/manual/function.intval.php