Large numbers in PHP are not what they seem to be

前端 未结 3 1586
独厮守ぢ
独厮守ぢ 2021-01-27 20:07

I agree with this

php > var_dump(number_format(10000000000000000000000)); // 10^22
php shell code:1:
string(30) \"10,000,000,000,000,000,000,000\"
         


        
3条回答
  •  离开以前
    2021-01-27 20:29

    Change the precisiona in php.ini or use ini_set and apply cast in your var

    ini_set('precision', 2048);
    $number1 = (float) "0.00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001";
    $number3 = (float) "0.000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001";
    
    $test1 = (0 == $number1);
    $test2 = (0 == $number3);
    

提交回复
热议问题