繁体   English   中英

浮点“错误”是PHP 64位

[英]Floating point 'error' is php 64bit

使用以下代码:

<?php
  $balance = (float)255744.12340511001247912645339965820312;
  print_r($balance);
?>

在32位计算机上,我得到:

255744.12340511

在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 );

如果您有权访问配置,则可能会稍快一些。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM