The is_float Function
The is_float
function checks if the passed variable is a floating-point number (float type).
It returns true
if the variable contains a floating-point number, and false
otherwise.
Syntax
is_float(mixed $var): bool
Example
Let's check different variable types:
<?php
$a = 3.14;
$b = 42;
$c = "3.14";
var_dump(is_float($a));
var_dump(is_float($b));
var_dump(is_float($c));
?>
Code execution result:
true
false
false
Example
Let's check the result of a mathematical operation:
<?php
$res = 10 / 3;
var_dump(is_float($res));
?>
Code execution result:
true
Example
Let's check type casting:
<?php
$val = (float) 5;
var_dump(is_float($val));
?>
Code execution result:
true
See Also
-
the
is_int
function,
which checks if a variable is an integer -
the
is_numeric
function,
which checks if a variable is a number or a string containing a number -
the
gettype
function,
which returns the type of a variable