Types7 min readExamples run on PHP 8.5.10

is_double()

Learn how is_double(), the alias of is_float(), tests whether a value is a float in PHP 8.4, with examples, edge cases and common mistakes.

Signature

is_double(mixed $value): bool

Purpose

is_double() answers one question: is the value you passed currently of PHP's float type? It returns true for floating-point numbers and false for everything else. According to the manual, it is an alias of is_float(). Both names call the same underlying check, so they behave identically.

The name comes from the idea of a "double-precision" number. In PHP's type system there is just one floating-point type, called float. When you write new code, is_float() is the name that matches the type, but is_double() is still useful to recognise when you read older code.

Signature

Parameters and defaults

  • $value is the only parameter. It accepts any PHP value: scalars, arrays, objects, null and resources. There are no optional parameters and no defaults.

Return value and failure cases

The function returns a bool:

  • true if $value has the type float.
  • false for every other type, including integers, strings (even numeric ones), booleans, null, arrays and objects.

The function does not throw for ordinary values and does not emit warnings. It inspects the type only and never converts the value, so nothing can "fail" beyond returning false. It also does not care whether a variable is defined as long as you can pass it; an undefined variable would raise its normal warning before the call.

Example 1: Basic type checks

The check looks at the type, not at how the value looks when printed. A numeric string such as '2.5' is still a string.

Example
<?php
$samples = [
    'float literal' => 1.5,
    'integer' => 3,
    'numeric string' => '2.5',
    'null' => null,
];
foreach ($samples as $label => $value) {
    echo $label, ': ', is_double($value) ? 'true' : 'false', "\n";
}
Output
float literal: true
integer: false
numeric string: false
null: false

Example 2: Results of calculations

The type of an arithmetic result depends on the operands. The / operator returns an integer when both operands are integers and the division is exact, and a float otherwise. This surprises many people.

Example
<?php
$results = [
    'exact division' => 10 / 2,
    'fractional division' => 10 / 4,
    'float cast' => (float) '7',
    'int plus float' => 1 + 1.0,
    'intdiv' => intdiv(10, 2),
];
foreach ($results as $label => $value) {
    echo $label, ': ', is_double($value) ? 'true' : 'false', "\n";
}
Output
exact division: false
fractional division: true
float cast: true
int plus float: true
intdiv: false

Example 3: Special float values and the alias

NAN and the infinities are still floats, and a result that overflows the integer range becomes a float too. The example also confirms that is_float() gives the same answer for each value.

Example
<?php
$checks = [NAN, INF, -INF, 1e3, PHP_INT_MAX + 1];
$results = [];
foreach ($checks as $value) {
    $results[] = is_double($value) === is_float($value) && is_double($value);
}
echo json_encode($results), "\n";
Output
[true,true,true,true,true]

Edge cases

  • Whole-number floats: 2.0 and 1e3 are floats. Having no fractional part does not make a value an integer.
  • NAN and INF: Both are floats, so is_double(NAN) is true. To detect a usable number, combine the check with is_nan() or is_finite().
  • Integer overflow: Arithmetic that exceeds PHP_INT_MAX produces a float, so the type can change in the middle of a calculation.
  • Numeric strings: '1.5' returns false. Use is_numeric() if you want to accept numeric strings, or cast first if you really intend to convert.
  • Strict typing does not matter: The function only inspects the value it receives, so declare(strict_types=1) does not change the result.

Common mistakes

  1. Expecting numeric strings to pass. Input from forms, query strings and JSON text fields is often a string. is_double('3.14') is false.
  2. Assuming division always returns a float. 10 / 2 is the integer 5. If you need a float, cast one operand or use 10 / 2.0.
  3. Using it as a "is a number" test. Integers are not floats. To accept both, use is_int($x) || is_float($x) or is_numeric() when strings are acceptable.
  4. Treating NAN as invalid input automatically. Because it is a float, the type check passes. Validate the value separately.
  5. Mixing alias names inconsistently. The two names are equivalent, so pick one in a project and keep using it for readability.
  • is_float(): the function this one is an alias of.
  • is_int() and is_integer(): test for the integer type.
  • is_numeric(): accepts integers, floats and numeric strings.
  • is_nan(), is_finite() and is_infinite(): inspect special float values.
  • floatval() and (float): convert a value to a float.
  • gettype() and get_debug_type(): report the type name of a value.

Recap

is_double() is an alias of is_float() with the signature is_double(mixed $value): bool. It returns true only when the value's type is float, including NAN and infinities, and false otherwise. It never converts values, so numeric strings and integers return false. Remember how arithmetic decides the result type, and combine the check with other validators when you need finite or numeric input.

Tested examples

Basic type checks
<?php
$samples = [
    'float literal' => 1.5,
    'integer' => 3,
    'numeric string' => '2.5',
    'null' => null,
];
foreach ($samples as $label => $value) {
    echo $label, ': ', is_double($value) ? 'true' : 'false', "\n";
}
Output
float literal: true
integer: false
numeric string: false
null: false
Results of calculations
<?php
$results = [
    'exact division' => 10 / 2,
    'fractional division' => 10 / 4,
    'float cast' => (float) '7',
    'int plus float' => 1 + 1.0,
    'intdiv' => intdiv(10, 2),
];
foreach ($results as $label => $value) {
    echo $label, ': ', is_double($value) ? 'true' : 'false', "\n";
}
Output
exact division: false
fractional division: true
float cast: true
int plus float: true
intdiv: false
Special float values and the alias
<?php
$checks = [NAN, INF, -INF, 1e3, PHP_INT_MAX + 1];
$results = [];
foreach ($checks as $value) {
    $results[] = is_double($value) === is_float($value) && is_double($value);
}
echo json_encode($results), "\n";
Output
[true,true,true,true,true]