简体   繁体   English

如何使用PHP将小数舍入到下一位

[英]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.11.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中实现呢?

Take a look at php's ceil() . 看看php的ceil()

echo ceil(4.3);    // 5
echo ceil(9.999);  // 10
echo ceil(-3.14);  // -3

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM