繁体   English   中英

四舍五入到最接近的整数

[英]Rounding up to the nearest whole number

我已经搜索了很长时间,似乎找不到任何关于此的内容。 如何将一个数字四舍五入到最接近的整数? 我正在使用数组中的对象数并将其除以 3。假设 [array count] 为 10,我希望得到 4 作为 10/3 的结果。 或者 [array count] 是 23,我想得到一个 8。我该怎么做? 提前致谢。

请务必输入您要四舍五入的数字:

int roundedNumber = ceil((double)number/3);

否则 integer 算术将被截断。

ceil() function 就是你要找的。

暂无
暂无

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

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