KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
When I call Math.ceil(5.2) the return is the double 6.0 . My natural inclination 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 a double rather than a long when the result is an integer? I think understanding the reason behind it might help me understand Java a bit better. It also might help me figure out if I'll get myself into trouble by casting to a long , e.g. is long b = (long)Math.ceil(a); always what I think it should be? I fear there could be some boundary cases that are problematic.
Tags (comma-separated)
Save Edits
Cancel