【发布时间】:2012-06-17 12:21:11
【问题描述】:
假设我想在Java 中将float 舍入为int。
例如,
roundUp(0.2) = 1
roundUp(0.7) = 1
roundUp(1.3) = 2
...
我想打电话给Math.ceil 和Math.round 这样做,但java.lang.Math 不提供ceil(float)。它仅提供ceil(double)。所以我的float 被提升为double,ceil(double) 返回double,round(double) 返回long,而我需要将float 向上取整为int(而不是long)。
现在我想知道为什么java.lang.Math 只有ceil(double) 而没有ceil(float)。
【问题讨论】:
-
我有点高兴地注意到,您的示例中的数字是双精度数,而不是浮点数!
标签: java floating-point integer