I want to be able to 'round' up any double
value to the closest higher integer, even if the value itself is already an integer value.
Math.ceil(2)
returns 2
, since 2
is already equal to an integer value. I need a function that would return 3
in this case.
I can easily code this myself but am curious whether this already exists in the JDK.
EDIT: In the likely case that I will just code this myself given how trivial I think this is, please tell me if the following code looks okay to you:
public static double convertToNearestLargerIntValue(double value){
return Math.floor(value + 1.0);
}
如此简单,不需要JDK方法。
Math.floor(value) + 1
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.