如何使用PHP将分数舍入到下一个数字
问题描述:
I know about php's built in round()
function, which return 2
for 1.6
. But it return 1
for 1.1
. I want to return the next number if the given number has a fractional part. For example, I want to return 2
for 1.1
, or 1.01
, or even 1.0001
. But I don't want to return the same for 1.0
, which may return 1
itself. How can I achieve this in PHP?
我知道php内置的 round() code>函数,返回
2 code>
1.6 code>。 但是它为
1.1 code>返回
1 code>。 如果给定的数字有小数部分,我想返回下一个数字。 例如,我想为
1.1 code>,或
1.01 code>,甚至
1.0001 code>返回
2 code>。 但我不想为
1.0 code>返回相同的内容,这可能会返回
1 code>本身。 我怎样才能在PHP中实现这一点? p>
div>
答
Use ceil()
to round up to the next number
echo ceil(1.0); // will echo 1