Difference between float and double in php?

后端 未结 4 1341
[愿得一人]
[愿得一人] 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:25

    As of PHP 7.0.6 on Windows, comparing this command without xdebug:

    $ php -r 'var_dump(28.4);'
    float(28.4)
    

    and with xdebug:

    $ php -r 'var_dump(28.4);'
    Command line code:1:
    double(28.4)
    

    Note that this only changes var_dump() output, but not the actual memory management.

    This may address some concerns why you see double instead of float shown in var_dump in some other machines.

    Also, with or without xdebug, gettype still returns string(6) "double".

提交回复
热议问题