douyinzha5820 2014-07-06 08:29
浏览 221

PHP:bigint数字出错

I've got a strange error. See the code

    $val1 = pow(2, 64);
    $val2 = $val1 - 1;
    echo number_format($val1, 0, '', '') . "<br/>";
    echo number_format($val2, 0, '', '') . "<br/>";

and it`s output

18446744073709551616
18446744073709551616

Why $val2 has value 18446744073709551616 when it must be 18446744073709551615?

  • 写回答

1条回答 默认 最新

  • dongpan1308 2014-07-06 08:36
    关注

    It's because $val1 became float and floating precision isn't that high. Look at Float precision Just look at example from manual floor((0.1+0.7)*10) should be rather 8 but on my PC it also return 7 (as in manual)

    If you want to use such big numbers you should probably use dedicated PHP libraries or BCMath

    评论

报告相同问题?

悬赏问题

  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改