The is_float method can be used to check if a variable is a float type or not.
is_float(mixed $value): bool
The is_float method returns true if the passed value is a float type. Otherwise, it returns false.
<?php$test = 10.1;printIsFloat($test);$test = 100.0;printIsFloat($test);$test = 10;printIsFloat($test);$test = '1.1';printIsFloat($test);function printIsFloat($test){echo "The Value is: ";var_dump($test);echo "Is Float: ";var_dump(is_float($test));echo "---------\n\n";}?>
In the code above:
We use the is_float method to check if a variable is of float type or not.
For the values 10.1 and 100.0, the is_float method returns true.
But for the values 10(int) and '1.1'(string), the is_float method returns false because they are not float type variables.