duanliaoyu8419 2010-02-19 03:30
浏览 77

使用PHP中的任意精度库进行舍入

I asked a question earlier about how to deal with rounding issues with floating point numbers in PHP, and was pointed to the bc and gmp libraries.

I've looked at the functions in these libraries but nothing jumped out at me when I was looking for one to round off the number.

How do you accurately round using these libraries?

  • 写回答

1条回答 默认 最新

  • dongyu9850 2010-02-19 03:35
    关注

    In How to ceil, floor and round bcmath numbers?, the answer gives you an implementation of bcround function, which utilizes its own bcfloor and bcceil function which seems to work.

    As a test, here is what you asked for in your comment.

    echo bcround(16.99225, 4); // outputs 16.9923 
    
    评论

报告相同问题?

悬赏问题

  • ¥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美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号