Dmitry Makovetskiyd Dmitry Makovetskiyd - 2 years ago 93
PHP Question

Checking if a string is a double or not

I am trying to check in php if a string is a double or not.

Here is my code:


$num is a string..The problem is that even when there is an int it gives true. Is there a way to check if it is a float and not an int!?

Answer Source
// Try to convert the string to a float
$floatVal = floatval($num);
// If the parsing succeeded and the value is not equivalent to an int
if($floatVal && intval($floatVal) != $floatVal)
    // $num is a float
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download