doude1917 2014-07-07 08:41
浏览 72
已采纳

PHP round()返回意外值

I have a double value of 2.6647 which I am trying to round mathematically correct to 2 decimal places.

I am expecting a return value of 2.67.

7 (the last decimal place) should round 4 (the second-last decimal place) up to 5, 5 should round 6 (the third-last decimal place) up to 7.

$value = 2.6647;
echo round( $value, 2, PHP_ROUND_HALF_UP );

But instead I receive 2.66. Why is this happening?

PHP Version is 5.3.28.

  • 写回答

4条回答 默认 最新

  • doulian7252 2014-07-07 08:47
    关注

    Rounding to n decimals is driven by n+1th decimal. In this case the third one decimal is 4, so the number is rounded down to 2.66.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 孟德尔随机化怎样画共定位分析图
  • ¥18 模拟电路问题解答有偿速度
  • ¥15 CST仿真别人的模型结果仿真结果S参数完全不对
  • ¥15 误删注册表文件致win10无法开启
  • ¥15 请问在阿里云服务器中怎么利用数据库制作网站
  • ¥60 ESP32怎么烧录自启动程序
  • ¥50 html2canvas超出滚动条不显示
  • ¥15 java业务性能问题求解(sql,业务设计相关)
  • ¥15 52810 尾椎c三个a 写蓝牙地址
  • ¥15 elmos524.33 eeprom的读写问题