According to Javadoc, it seems to be
Double#valueOf(String)
but Eclipse links withDouble#valueOf(double)
.
I couldn't find the place in Javadoc where it would suggest that the String
overload would get called in this situation, but Eclipse is right: there is no implicit conversion from float
to String
, but there is an implicit conversion from float
to double
, so Double#valueOf(double)
is the correct overload.
Calling Double.valueOf with float round the result
It does not "round" the result, it changes its representation to fit double
, which has higher precision. However, neither float
nor double
could represent 0.1
exactly, because it cannot be represented as a sum of negative powers of 2
. If you use 0.25
instead of 0.1
, this would not happen, because 0.25
is 2 ^ -2
, and therefore can be represented precisely in both float
and double
.