PHP is_float() Function
Last Updated :
04 Apr, 2023
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
$variable_name1 = 67.099;
$variable_name2 = 32;
$variable_name3 = "abc";
$variable_name4 = FALSE;
if ( is_float ( $variable_name1 ))
echo " $variable_name1 is a float value. \n";
else
echo " $variable_name1 is not a float value. \n";
if ( is_float ( $variable_name2 ))
echo " $variable_name2 is a float value. \n";
else
echo " $variable_name2 is not a float value. \n";
if ( is_float ( $variable_name3 ))
echo " $variable_name3 is a float value. \n";
else
echo " $variable_name3 is not a float value. \n";
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
function square( $num )
{
return ( is_float ( $num ));
}
echo square(9.09) ."\n";
echo square(FALSE) ."\n";
echo square(14) ."\n";
echo square(56.30) ."\n";
?>
|
Output:
1
1
Reference: http://php.net/manual/en/function.is-float.php
Share your thoughts in the comments
Please Login to comment...