Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

is there a "double" type in PHP

Tags:

php

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

like image 507
lovespring Avatar asked Jul 07 '10 13:07

lovespring


3 Answers

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 .

like image 100
Felix Kling Avatar answered Oct 10 '22 08:10

Felix Kling


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).

§6.2.5.10

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)

like image 38
Artefacto Avatar answered Oct 10 '22 10:10

Artefacto


http://php.net/manual/en/language.types.float.php

like image 2
thetaiko Avatar answered Oct 10 '22 10:10

thetaiko