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

phpis_float(mixed $var): bool

Example

Let's check different variable types:

php<?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:

phptrue
false
false

Example

Let's check the result of a mathematical operation:

php<?php
  $res = 10 / 3;
  var_dump(is_float($res));
?>

Code execution result:

phptrue

Example

Let's check type casting:

php<?php
  $val = (float) 5;
  var_dump(is_float($val));
?>

Code execution result:

phptrue

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