[英]How to round a fraction into next digit using PHP
I know about php's built in round()
function, which return 2
for 1.6
. 我知道php的内置
round()
函数,该函数返回1.6
2
。 But it return 1
for 1.1
. 但它返回
1
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
. 例如,我想为
1.1
或1.01
甚至1.0001
返回2
。 But I don't want to return the same for 1.0
, which may return 1
itself. 但是我不想为
1.0
返回相同的值,它本身可能返回1
。 How can I achieve this in PHP? 如何在PHP中实现呢?
Use ceil()
to round up to the next number 使用
ceil()
舍入到下一个数字
echo ceil(1.0); // will echo 1
http://www.php.net/manual/en/function.ceil.php http://www.php.net/manual/en/function.ceil.php
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.