how to print a floating point number?
807607Oct 15 2006 — edited Oct 16 2006when you print a float with System.out.print() the answer loses precision. how can i print the exact value of my float?
my example:
i have a floating point number that is in ieee format.
when i do: System.out.print(Integer.toBinaryString(Float.floatToIntBits(myNumber)));
i get this:
0 01111111 10100000000000000000001
that is a sign bit of 0 exponent of 0 and a significand of 1.10100000000000000000001
however when i do System.out.print(myNumber);
i get this: 1.6250001
if i cast to a double then print i get this:
1.6250001192092896
i suspect that even after casting to a double im not getting the full answer. can anyone tell me how to print the entire float?
Thanks.