Difference between float and double in php?

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

    In PHP 7.0.14

    function test(double $a) {
        var_dump($a);
    }
    test(2.2111);
    

    Returns "Fatal error: Uncaught TypeError: Argument 1 passed to test() must be an instance of double, float given".

    function test(float $a) {
        var_dump($a);
    }
    test(2.2111);
    

    Prints 2.2111 to the screen.

提交回复
热议问题