Suppose I would like to round up float to int in Java.
For instance,
roundUp(0.2) = 1
roundUp(0.7) = 1
roundUp(1.3) = 2
...
I would like to call Math.ceil and Math.round to do that but java.lang.Math does not provide ceil(float). It provides only ceil(double). So my float is promoted to double silently, ceil(double) returns double and round(double) returns long while I need to round up float to int (not long).
Now I wonder why java.lang.Math has only ceil(double) and does not have ceil(float).
You can do:
If you know that
valueis a float then you can cast the result back tofloatorint.It makes no sense for the Java library to provide both
ceil(float)andceil(double)as all float arguments can be passed to theceil(double)method with the same result.