Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

how to print a floating point number?

807607Oct 15 2006 — edited Oct 16 2006
when 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.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 13 2006
Added on Oct 15 2006
6 comments
371 views