PHP is_float() Function
PHP is_float() is an inbuilt function in PHP. The is_float() function is used to find whether a variable is a float or not.
Syntax:
boolean is_float($variable_name)
Parameter: This function contains a single parameter as shown in the above syntax and described below
- $variable_name: the variable we want to check.
Return value: It is a boolean function so returns TRUE when $variable_name is an integer, otherwise FALSE.
The below example illustrates the working of the function is_float().
Example 1:
PHP
<?php // php code demonstrate working of is_float() $variable_name1 = 67.099; $variable_name2 = 32; $variable_name3 = "abc"; $variable_name4 = FALSE; // $variable_name1 is float, gives TRUE if ( is_float ( $variable_name1 )) echo " $variable_name1 is a float value. \n"; else echo " $variable_name1 is not a float value. \n"; // $variable_name2 is not float, gives FALSE if ( is_float ( $variable_name2 )) echo " $variable_name2 is a float value. \n"; else echo " $variable_name2 is not a float value. \n"; // $variable_name3 is not float, gives FALSE if ( is_float ( $variable_name3 )) echo " $variable_name3 is a float value. \n"; else echo " $variable_name3 is not a float value. \n"; // $variable_name4 is not float, gives FALSE if ( is_float ( $variable_name4 )) echo "FALSE is a float value. \n"; else echo "FALSE is not a float value. \n"; ?> |
Output:
67.099 is a float value. 32 is not a float value. abc is not a float value. FALSE is not a float value.
Example 2:
PHP
<?php // PHP code demonstrate working of is_float() function square( $num ) { return ( is_float ( $num )); } echo square(9.09) ."\n"; // outputs '1'. echo square(FALSE) ."\n"; // gives no output. echo square(14) ."\n"; // gives no output. echo square(56.30) ."\n"; // outputs '1' ?> |
Output:
1 1
Reference: http://php.net/manual/en/function.is-float.php
Contact Us