我正在尝试使用 PHP 表示 BIGINT 值(它们是表中的键),并测试 PHP 如何将大数字作为字符串/浮点值处理,我编写了一个小测试:
<?php
echo "PHP_INT_MAX=".PHP_INT_MAX."\n";
$x = "9223372036854775107";
echo "Defining x as : 9223372036854775107\n";
$y = floatval($x);
echo "float of x: ".$y."\n";
echo "float to string using strval: ".strval($y)."\n";
echo "float to string using sprintf: ".sprintf( "%.0f", $y)."\n";
?>
所以我对输出很好奇:
PHP_INT_MAX=9223372036854775807
Defining x as : 9223372036854775107
float of x: 9.2233720368548E+18
float to string using strval: 9.2233720368548E+18
float to string using sprintf: 9223372036854774784
那么为什么我得到的值不匹配?(php.ini 文件中的精度 = 14)