PHP如何四舍五入到小数点后两位?
问题描述:
我需要将PHP中的小数点四舍五入到两位小数,以便:
I need to round down a decimal in PHP to two decimal places so that:
49.955
成为...
49.95
我尝试过 number_format ,但这只是将值四舍五入到 49.96 .我不能使用 substr ,因为该数字可能较小(例如7.950).到目前为止,我还没有找到答案.
I have tried number_format, but this just rounds the value to 49.96. I cannot use substr because the number may be smaller (such as 7.950). I've been unable to find an answer to this so far.
非常感谢您的帮助.
答
这可以起作用:floor($number * 100) / 100