Cast float to bool PHP

> Convert float to boolean

Description
Cast float to boolean


$val = (bool)0.0;   // false, only 0.0 value is false.
$val = (boolean)0.0; // false, same as (bool)
$val = (bool)-1.0;   // true, any non-zero value is true.

$val = filter_var(1.0, FILTER_VALIDATE_BOOLEAN); // true, only 1.0 value is true.
$val = filter_var(0.0, FILTER_VALIDATE_BOOLEAN); // false
$val = filter_var(1.1, FILTER_VALIDATE_BOOLEAN); // false
$val = filter_var(-1.0, FILTER_VALIDATE_BOOLEAN); // false

SEE ALSO