Skip to Main Content

New to Java

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!

convert float to double

843785Sep 17 2008 — edited Sep 18 2008
Hi,

I want to put a float value to double variable.
float f  = 1.0000345f;
double d = f;
System.out.println("float " + f);//Prints 1.0000345
System.out.println("double " + d);//Prints 1.0000344514846802
Why does the double variable contains a different value.
Is there a way to overcome this issue.

Thanks,
Chamal.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 16 2008
Added on Sep 17 2008
20 comments
4,529 views