Hi,
there's this annoying little conversion problem that is getting in my way.
I was under the impression that a widening conversion from a float to a double primitive (which happens implicitly without a cast) would conserve the original value completely. This however doesn't seem to be the case. Here's an example:
The result is:
The problem is that when I explicitly want to store the value 3.02 in a float and it gets converted to a double, this double variable does not contain exactly what was in the float.
One thought is that double is not able to hold the 3.02 value exactly, but this is disproven by the 5th and 6th line of code where the conversion is done via a
String object (how resource-wasting can you get
). Via this method the double does contain the value originally intended.
Another idea is that the original float variable didn't really contain the 3.02 but rather an approximation, and that this approximation shows up as a real intended value when the conversion to double happens.
Net result is that I have an intended value in the form of a float and I can only get this value exactly in a double by doing the conversion via a String object which is incredibly resource wasting... Apparently the widening conversion between float and double isn't as preserving as I thought.
Am I missing something here? Suggestions welcome.
Raf.