我怎样才能确保一个浮动将始终与PHP四舍五入? [英] How can I make sure a float will always be rounded up with PHP?
本文介绍了我怎样才能确保一个浮动将始终与PHP四舍五入?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想确保PHP中的浮点数是在小数点存在的情况下进行的,而不用担心数学舍入规则。这个功能如下:
1.1到2
1.2到2
1.9到2
2.3至3
2.8至3
我知道 round()
函数存在,但我没有看到任何函数四舍五入,如果任何十进制被发现。有没有简单的方法来做到这一点?
ceil
功能: $ number = ceil(1.1); // 2
I want to make sure a float in PHP is rounded up if any decimal is present, without worrying about mathematical rounding rules. This function would work as follows:
1.1 to 2
1.2 to 2
1.9 to 2
2.3 to 3
2.8 to 3
I know the round()
function exists but I don't see any function for rounding up if any decimal is found. Is there any easy way to do this?
解决方案
Use the ceil
function:
$number = ceil(1.1); //2
这篇关于我怎样才能确保一个浮动将始终与PHP四舍五入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文