php舍入到下一个整数 [英] php round to the next whole number
问题描述
在PHP中,我需要将一个数字四舍五入到下一个整数.例如,在我的程序中,我正在使用以下回合.
In PHP, I need to round off a number to the next whole number. For example, in my program, I am using the round as below.
$val = round(count($names)/15);
如果 count($ names)是1.2,我需要将其四舍五入为2而不是1.我尝试执行以下方法.
If count($names) is 1.2, I need it to be rounded off to 2 instead of 1. I tried to do the below approach.
$val = round(count($names)/15) + 1;
但是,在上述方法中,如果我将 count($ names)设置为1.6,则当我将其递增1时,它将四舍五入为3.
However, in the above approach, if I have count($names) as 1.6, It is getting rounded off to 3 as I increment it by 1.
有没有办法将小数点后的数值四舍五入到下一个整数?
Is there a way where no matter what the decimal value is, it needs to be rounded off to the next whole number?
推荐答案
如何使用ceil()
http://php.net/manual/en/function.ceil.php
然后您的代码将变为:
$val = ceil(count($names)/15);
这篇关于php舍入到下一个整数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!