Signature
is_double(mixed $value): boolPurpose
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
$valueis the only parameter. It accepts any PHP value: scalars, arrays, objects,nulland resources. There are no optional parameters and no defaults.
Return value and failure cases
The function returns a bool:
trueif$valuehas the typefloat.falsefor 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.
$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";
}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.
$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";
}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.
$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";[true,true,true,true,true]
Edge cases
- Whole-number floats:
2.0and1e3are floats. Having no fractional part does not make a value an integer. NANandINF: Both are floats, sois_double(NAN)istrue. To detect a usable number, combine the check withis_nan()oris_finite().- Integer overflow: Arithmetic that exceeds
PHP_INT_MAXproduces a float, so the type can change in the middle of a calculation. - Numeric strings:
'1.5'returnsfalse. Useis_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
- Expecting numeric strings to pass. Input from forms, query strings and JSON text fields is often a string.
is_double('3.14')isfalse. - Assuming division always returns a float.
10 / 2is the integer5. If you need a float, cast one operand or use10 / 2.0. - Using it as a "is a number" test. Integers are not floats. To accept both, use
is_int($x) || is_float($x)oris_numeric()when strings are acceptable. - Treating
NANas invalid input automatically. Because it is a float, the type check passes. Validate the value separately. - Mixing alias names inconsistently. The two names are equivalent, so pick one in a project and keep using it for readability.
Related functions
is_float(): the function this one is an alias of.is_int()andis_integer(): test for the integer type.is_numeric(): accepts integers, floats and numeric strings.is_nan(),is_finite()andis_infinite(): inspect special float values.floatval()and(float): convert a value to a float.gettype()andget_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
$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";
}
float literal: true integer: false numeric string: false null: false
$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";
}
exact division: false fractional division: true float cast: true int plus float: true intdiv: false
$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";
[true,true,true,true,true]