如题所述
查看一下JAVA API文档
ceil
public static double ceil(double a)
返回最小的(最接近负无穷大)double 值,该值大于等于参数,并等于某个整数。特殊情况如下:
如果参数值已经等于某个整数,那么结果与该参数相同。
如果参数为 NaN、无穷大、正 0 或负 0,那么结果与参数相同。
如果参数值小于 0,但是大于 -1.0,那么结果为负 0。
注意,Math.ceil(x) 的值与
-Math.floor(-x) 的值完全相同。
参数:
a - 一个值。
返回:
最小(最接近负无穷大)浮点值,该值大于等于该参数,并等于某个整数。
温馨提示:答案为网友推荐,仅供参考
第1个回答 推荐于2017-10-03
Java math.ceil代表取最小值,这个值很有可能会超过整数范围,所以得用double来表示,英文API开发文档解释如下:
Not really, considering that a double can be a much higher magnitude than an int. You wouldn't want to overflow an int with the large value that a double could be.
Just to show you what I mean:
Double.MaxValue = 1.7976931348623157E+308
Integer.MaxValue = 2,147,483,647
So you could have a double that is 3,000,000,000.50 and ceiling it, which would overflow the max value of an int.
Not really, considering that a double can be a much higher magnitude than an int. You wouldn't want to overflow an int with the large value that a double could be.
Just to show you what I mean:
Double.MaxValue = 1.7976931348623157E+308
Integer.MaxValue = 2,147,483,647
So you could have a double that is 3,000,000,000.50 and ceiling it, which would overflow the max value of an int.
第2个回答 2015-06-27
java的api中Math.ceil返回最小的(最接近负无穷大)double 值,该值大于等于参数,并等于某个整数。规定就是返回double值。