Tutorialspoint.dev

PHP | is_float() Function

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 above syntax and 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.

Below example illustrates the working of the function is_float().



Example 1::

<?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. ";
else
    echo "$variable_name1 is not a float value. ";
  
// $variable_name2 is not float, gives FALSE
if (is_float($variable_name2))
    echo "$variable_name2 is a float value. ";
else
    echo "$variable_name2 is not a float value. ";
  
// $variable_name3 is not float, gives FALSE
if (is_float($variable_name3))
    echo "$variable_name3 is a float value. ";
else
    echo "$variable_name3 is not a float value. ";
  
// $variable_name4 is not float, gives FALSE
if (is_float($variable_name4))
    echo "FALSE is a float value. ";
else
    echo "FALSE is not a float value. ";
?>

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 code demonstrate working of is_float()
  
function square($num)
{
    return (is_float($num));
}
  
echo square(9.09) ." "// outputs '1'.
echo square(FALSE) ." "; // gives no output.
echo square(14) ." ";    // gives no output.
echo square(56.30) ." "// outputs '1'
  
?>

Output:

1


1

reference : http://php.net/manual/en/function.is-float.php



This article is attributed to GeeksforGeeks.org

leave a comment

code

0 Comments

load comments

Subscribe to Our Newsletter