简体   繁体   English

如何舍入小数?

[英]How to round up a decimal?

How can I use round() to round a number to the superior number as soon as there is a decimal? 如果有小数,我怎样才能使用round()将数字四舍五入到高位数?

For example: 例如:

1.00001      = 2
1.1          = 2
1.4785834975 = 2
1.00         = 1
1.99         = 2
3.01         = 4

Yes, what you are looking for is called ceil 是的,你要找的是ceil

<?php
echo ceil(4.3);    // 5
echo ceil(9.999);  // 10
echo ceil(-3.14);  // -3
?>

This might be helpful for you: 这可能对您有所帮助:

floor() will go down. floor()会下降。

ceil() will go up. ceil()会上升。

round() will go to nearest by default. round()将默认为最接近。

<?php
echo ceil(3.4);    // 4
echo ceil(8.89);  // 9
?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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