【问题标题】:Difference PHP_INT_MAX PHP_INT_SIZE precision?差异 PHP_INT_MAX PHP_INT_SIZE 精度?
【发布时间】:2015-08-31 23:33:09
【问题描述】:

和有什么区别

  1. PHP_INT_MAX
  2. PHP_INT_SIZE

php.ini 的精度 我有 Windows 8.1(64bit),输入代码:

ini_set('precision', 50);
$t = 12345678901234567890123456789012345678901234567890;
echo $t; //the result is 12345678901234566660398341115085767575755770822656

【问题讨论】:

    标签: php php-ini


    【解决方案1】:

    http://php.net/manual/en/reserved.constants.php

    PHP_INT_MAX(整数)
    此 PHP 版本支持的最大整数。通常是 int(2147483647)。自 PHP 5.0.5 起可用
    [...]
    PHP_INT_SIZE(整数)
    此 PHP 版本中整数的大小(以字节为单位)。自 PHP 5.0.5 起可用

    这些值可能是例如PHP_INT_MAX=2147483647 和 PHP_INT_SIZE=4,即整数类型是 32 位“宽”(4 字节),范围从 –2147483648 到 2147483647。

    精度在http://docs.php.net/manual/en/ini.core.php#ini.precision 解释为:

    精度integer
    以浮点数显示的有效位数。

    所以它不会影响整数而是浮点数。例如

    <?php
    $f = .123456789;
    ini_set('precision', 8);
    echo $f, "\r\n";
    
    ini_set('precision', 2);
    echo $f, "\r\n";
    

    打印

    0.12345679
    0.12
    

    【讨论】:

      猜你喜欢
      • 2012-07-18
      • 2015-04-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-06-24
      • 1970-01-01
      • 1970-01-01
      • 2018-01-06
      相关资源
      最近更新 更多