Re: is_int() and is_double
| From: | Christian Reiniger | Date: | Thu, 25 Oct 2001 08:57:39 +0000 |
| Subject: | Re: is_int() and is_double | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-72218@lists.php.net to get a copy of this message | ||
On Wednesday 24 October 2001 20:26, Michael George wrote:
[...]
> The function is called after a form submission from HTML. When I enter
> 12 14
> I get:
> -----------------------------------------------------------------------
>-------- lookupProduct( 12, 14 )
> $partNum: 12 does appear to be a number, and not a double
> $serial: 14 does appear to be a number, and not a double
> -----------------------------------------------------------------------
>--------
>
> When I enter
> 12.5 14.8
> I get:
> -----------------------------------------------------------------------
>-------- lookupProduct( 12.5, 14.8 )
> $partNum: 12 does appear to be a number, and not a double
> $serial: 14 does appear to be a number, and not a double
> -----------------------------------------------------------------------
>--------
>
> Why is the function is_double() failing? I have an analagous problem
> with the is_int() function.
You get both values as strings from the form. is_numeric checks if the
variable is in some was a number (and returns true because it actually is
a string representation of a number).
is_int and is_double check whether the variable's current datatype
actually is "int" or "double"
See the manual.
Possible solution:
if (is_numeric ($a)) {
$a = (double) $a;
if (intval ($a) == $a)
echo "'$a' is integer";
else
echo "'$a' is double";
}
--
Christian Reiniger
LGDC Webmaster (http://lgdc.sunsite.dk/)
/* you are not expected to understand this */
- from the UNIX V6 kernel source