dongtiao2105 2014-05-21 22:39
浏览 352
已采纳

整数除以100是否会导致PHP中出现浮点错误?

I'm always wary of adding and subtracting floating point numbers, as they can cause some errors when truncating instead of round.

My question though: will an integer divided by 100 ever cause floating point errors in PHP?

I.e. is it "safe", should I always rely on round($x / 100, 2)?

  • 写回答

1条回答 默认 最新

  • dpquu9206 2014-05-21 22:41
    关注

    Yes. Actually, since 100 isn't a power of two, the result of $x / 100 will always be inexact unless $x is a multiple of 25. (You get 4 for free since 4 is a power of 2.)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 求推荐发表需要付费的深度学习遥感场景分类SCI期刊
  • ¥15 无法在java控制台录入文字
  • ¥15 flutter网页应用用python的http服务器访问速度慢
  • ¥15 VESTA绘图原子颜色显示异常
  • ¥15 天翼云搭建多ip l2tp
  • ¥15 python实现CAD识图
  • ¥15 如何实现在renpy中创建并应用不同大小尺寸对话框?
  • ¥15 table表格有一列是固定列 滑动到最下面时 固定的那一列有几行没显示出来
  • ¥20 单细胞数据注释时报错
  • ¥15 vscode编译ros找不到头文件,cmake.list文件出问题,如何解决?(语言-c++|操作系统-linux)