duanchuli5647 2014-05-16 19:33
浏览 222

在PHP中设置精度

I have installed PHP 5.5 on my laptop, who's running Windows. I'm accessing Smartsheet API, and I supposed to get a column id a number with 18 digits(or sometimes 17). But I get a scientific number:

1.5441916385627E+15, not 1544191638562692

I ran the script, in a Ubuntu server environment, and I see 1544191638562692. The same, a ran in a OS X Maverick environment, and it's the same the integer format.

I was searching for this matter, and seems to be the precision.

If I'm setting in php, the precision 14 for the OS X Maverick environment like this:

<?php
ini_set('precision', 14);

    echo (float)$col->id;
    // 1.5441916385627E+15
?>

I get also the scientific number.

Can anybody help me with an idea?

  • 写回答

3条回答 默认 最新

  • duan3019 2014-05-16 19:44
    关注

    You can output the numbers in the same way on all machines using the formatted string functions in PHP, see http://nl1.php.net/manual/en/function.sprintf.php for the documentation.

    So if you would like the integer as a whole you would use:

    printf("%u", $number);
    
    评论

报告相同问题?

悬赏问题

  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染