比方说我有:
echo 1/3;
它只打印出0.33333333333333,我能获得更多数字吗?
在precision
或其他配置位置编辑php.ini
配置变量或使用ini_set()
。
ini_set('precision', 22);
echo 1/3;
// 0.3333333333333333148296
即使我非常怀疑你真的需要那种精确度;-)
编辑
正如戈登所说:你迟早会在PHP中达到浮点精度限制(取决于指定的精度)。因此,如果您正在使用真正的高精度数学,那么更好的方法是使用BCMath Arbitrary Precision Mathematics扩展或GNU Multiple Precision扩展。
您可能想要查看BC任意精度php库qazxsw poi
设置是http://php.net/manual/en/book.bc.php:precision
但是,除了调试之外,我不会使用它。看看http://es.php.net/manual/en/ini.core.php