Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/290.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 浮点';错误';是64位吗_Php_Rounding - Fatal编程技术网

Php 浮点';错误';是64位吗

Php 浮点';错误';是64位吗,php,rounding,Php,Rounding,使用以下代码: <?php $balance = (float)255744.12340511001247912645339965820312; print_r($balance); ?> 在64位的机器上,我得到了 255744.123405 我(几乎)确信它与32位与64位机器无关,而是它在某个地方的设置。 我也不认为这是一个浮点问题,而是一个php舍入问题 我希望我的精度达到16位小数 我如何才能达到这样的精度水平?为了避免混淆,请回答我自己的问题,正如Amal M

使用以下代码:

<?php
  $balance = (float)255744.12340511001247912645339965820312;
  print_r($balance);
?>
在64位的机器上,我得到了

255744.123405
我(几乎)确信它与32位与64位机器无关,而是它在某个地方的设置。
我也不认为这是一个浮点问题,而是一个php舍入问题

我希望我的精度达到16位小数


我如何才能达到这样的精度水平?

为了避免混淆,请回答我自己的问题,正如Amal Murali正确指出的那样,设置为:

在ini文件中:

; The number of significant digits displayed in floating point numbers.
; http://php.net/precision
precision = 32

; When floats & doubles are serialized store serialize_precision significant
; digits after the floating point. The default value ensures that when floats
; are decoded with unserialize, the data will remain the same.
serialize_precision = 32
或者直接在脚本中

ini_set('precision', 32);
ini_set( 'serialize_precision', 32 );

如果您可以访问该配置,它可能会稍微快一点。

浮点数(在PHP中)的精度有限。但是您可以使用增加当前的精度。非常感谢,这就是问题所在,我现在将在加载脚本时设置精度(或在ini文件中,但这两种方式都不重要)。谢谢,我完全理解这可能有效,也可能无效,但您回答了我的问题,即为什么两台服务器上的值不相同。我想确认这是配置中的设置,而不是php中的限制。
ini_set('precision', 32);
ini_set( 'serialize_precision', 32 );