Difference between float and double in php?

后端 未结 4 1344
[愿得一人]
[愿得一人] 2020-12-02 14:05

I have this code

$vad = 1.1;

print gettype($vad);

var_dump($vad);

this will output:

double
float(1.1) 

4条回答
  •  北荒
    北荒 (楼主)
    2020-12-02 14:24

    For PHP, they are the same. http://www.php.net/manual/en/language.types.float.php :

    Floating point numbers (also known as "floats", "doubles", or "real numbers") can be specified using any of the following syntaxes: [...]

    The confusing part is why gettype (which you shouldn't use, anyway) returns "double" instead of "float". The answer is http://de2.php.net/manual/en/function.gettype.php:

    " double " (for historical reasons "double" is returned in case of a float , and not simply "float")

提交回复
热议问题