Dmitry Makovetskiyd Dmitry Makovetskiyd - 6 months ago 4x
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!?

// 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