我爱占星网 我爱占星网
首页
编程
java
php
前端
首页 编程 java php 前端

整数除以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)?

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.)

近期文章

  • 示例服装数据库架构。 (我究竟做错了什么?)
  • Actuate Birt Viewer
  • 使用JavaScript将PHP值传递到另一个页面时出错
  • 检查多维中是否存在两对值和键
  • 获得比修改的最后日期早三分钟的东西
  • 如何使用PHP数组从外部页面显示新闻源?
  • 将多个复选框值插入单个列 - SQL数据库
  • Facebook封面图片重新定位代码[关闭]
  • Rackspace,负载平衡,flush()和cURL
  • 在ZF2中为ZfcUser使用Bootstrap Modal?
  • 如何在cakephp中获取控制器中的值
  • 在Mandrill中循环播放电子邮件
  • PHP正则表达式对西里尔字符集不区分大小写
  • 使用php进行域和子域验证
  • PHP HTML Heredoc Parse错误:语法错误,意外'''
  • 如何在另一个函数中执行php函数?
  • 基于特定查询值的不同行输出
  • 通过动态更新内容显示用户定义的MySql结果数[php]
  • 根据php中元素的最后和第一个字符匹配排列数组元素
  • 在doophp中编写自定义查询

Copyright ©2022 我爱占星 All Rights Reserved.

浙ICP备2022030071号-1

部分图文来自网络,如有侵犯您的版权,请告诉我们删除

友情链接:代码精华