如何在PHP中基于小数点添加或减去金额 [英] How can I add or subtract amount based on decimal points in PHP
本文介绍了如何在PHP中基于小数点添加或减去金额的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何根据PHP / CI中的小数点添加或减去金额?即如果金额为5.11则应返回5,如果金额为5.66,则应返回6.如果小数大于50则减去+1,如果小于或等于50则减去减去
我尝试了什么:
我们可以使用十进制检测然后ceil和floor函数相应但是寻找是否有库或函数avaliable
解决方案
你所描述的只是正常的舍入(除非我遗漏了什么)
PHP通过圆形功能实现这一点。
round(5.11);
round(5.6);
圆形功能文档
PHP:round - Manual [ ^
How can I add or subtract amount based on decimal points in PHP / CI? I.e. if the amount is 5.11 it should return 5 and if amount is 5.66 it should return 6. Subtract +1 if decimal is greater then 50 and subtract if lesser or equal to 50
What I have tried:
We can use decimal detection and then ceil and floor function accordingly but seeking if there is library or function avaliable
解决方案
What you've described is just normal rounding (unless I am missing something)
PHP accomplishes this with the round function.
round(5.11);
round(5.6);
Round function documentation
PHP: round - Manual[^]
这篇关于如何在PHP中基于小数点添加或减去金额的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文