When I call Math.ceil(5.2) , double 6.0 returns. My natural tendency was to think that Math.ceil(double a) would return a long . From the documentation:
ceil(double a)
Returns the smallest (closest to negative infinity) double value that is not less than the argument and is equal to a mathematical integer.
But why return double instead of long when the result is an integer? I think that understanding the reason for this can help me understand Java a little better. It can also help me figure out if I get into trouble by adding to long , for example. this is
long b = (long)Math.ceil(a);
always, what do I think it should be? I am afraid that there may be some boundary cases that are problematic.
java double long-integer ceil
PengOne Sep 02 '11 at 17:26 2011-09-02 17:26
source share