if not, then how to declare a double type of number?
function testFloat(float $f)
{
return $f;
}
echo testFloat(1.2);
Catchable fatal error: Argument 1 passed to testFloat() must be an instance of float, double given
Update:
Regarding type hinting:
Type Hints can only be of the object and array (since PHP 5.1) type. Traditional type hinting with int and string isn't supported.
So I don't know, but probably you get the error because only array
and object
types are supported.
I am not exactly sure what you want, but there is only float
:
Floating point numbers (also known as "floats", "doubles", or "real numbers") can be specified using any of the following syntaxes:
<?php $a = 1.234; $b = 1.2e3; $c = 7E-10; ?>
and there you find also:
Converting to float
For information on converting strings to float , see String conversion to numbers. For values of other types, the conversion is performed by converting the value to integer first and then to float . See Converting to integer for more information. As of PHP 5, a notice is thrown if an object is converted to float .
The float
type in PHP is implemented internally as a C double
. The size of such type is unspecified by the C standard, which only requires that sizeof(float) <= sizeof(double) <= sizeof(long double)
.
There are three real floating types, designated as float, double, and long double.34) The set of values of the type float is a subset of the set of values of the type double; the set of values of the type double is a subset of the set of values of the type long double.
(from here)
http://php.net/manual/en/language.types.float.php
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With