在 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在如何对bcmath数字进行向上取整、向下取整和四舍五入?,答案为您提供了
bcround
函数的实现,它利用了自己的bcfloor
和bcceil
函数,这似乎可以工作。作为测试,这是您在评论中要求的内容。
In How to ceil, floor and round bcmath numbers?, the answer gives you an implementation of
bcround
function, which utilizes its ownbcfloor
andbcceil
function which seems to work.As a test, here is what you asked for in your comment.