incorrect float to double convertsion
807607Jan 3 2007 — edited Jan 5 2007Hi all.
While doing some programming in Java, I came across the following issue:
float a = 23.3
double b = 23.3
if i do
System.out.println(a)
or
System.out.println(b)
I will get: 23.3
So, now I do some castings.
float a = 23.3
double b = a
Doing the same as above with println() I will get:
a = 23.3
BUT
b = 21.2999906...
Now, turning it upside down:
double a = 23.3
float b = (float)a
I will get 23.3 for both, a and b.
So, can anyone tell me what's going on behinde the scenes? So far, I just don't get it :-(
Thanks
Marcel