Tim Tim - 1 month ago 7
PHP Question

Php floating if statement Confused

function is_decimal( $spaces )
{
return is_numeric( $spaces ) && floor( $spaces ) != $spaces;
}

if (is_decimal == true){
echo "Error 3: Decimal causing Error as carpark can't have decimal spaces available.";
}


This gives me an error even though the int is not a decimal (float). Can someone help me. Thanks
It works fine for a decimal but not for an int.

Answer

Simple, when you call a function with a parameter you have to pass a parameter!

function is_decimal( $spaces )
{
    return is_numeric( $spaces ) && floor( $spaces ) != $spaces;
}

$tst_var = 1.99
if (is_decimal($tst_var) == true){
    echo "Error 3: Decimal causing Error as carpark can't have decimal spaces available.";
}
Comments