java 四舍五入到整数?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5685927/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 12:18:38  来源:igfitidea点击:

Round Up Double to Whole Number?

javaandroid

提问by Coops5575

I have a double that contains the result of a calculation.

我有一个包含计算结果的双精度值。

i.e 2.123 etc

即 2.123 等

Is there a simple way where i can round up this number to the next number up i.e 3

有没有一种简单的方法可以将这个数字四舍五入到下一个数字,即 3

I have searched the forum, but only come up with how to round off to decimal places.

我已经搜索了论坛,但只想出了如何四舍五入到小数位。

cheers

干杯

回答by Jigar Joshi

Have you checked Math.ceil(double)?

你检查了Math.ceil(double)吗?