1

When converting the Float value of 3.14 to double whith this code:

Float my_float = new Float(3.14);
System.out.println("Float : " + my_float);
Double my_double = new Double (my_float.doubleValue());

System.out.println( "Double : " + my_double);

This is what is output:

Float : 3.14

Double : 3.140000104904175

How did the Double get the extra decimal places instead of retaining the original value of 3.14?

Emerrias
  • 15
  • 7
  • @denispyr There is a better duplicate. – Pascal Cuoq Jul 06 '14 at 20:44
  • A classical newbie question, but a float/double number that is not an integer is rarely exact. – Hot Licks Jul 06 '14 at 20:54
  • Also a duplicate fo http://stackoverflow.com/questions/17504833/why-converting-from-float-to-double-changes-the-value . Good answers both there and in http://stackoverflow.com/questions/916081 , perhaps they should be merged? – Pascal Cuoq Jul 06 '14 at 20:55

0 Answers0