0

I am attempting to convert a Float to a double but when I do the number is changing. I am having trouble understanding why because I thought doubles have higher precision than floats.

enter image description here

Float f = 111111111111f;
double d = f.doubleValue();
float ff = f.floatValue();

As seen in the above picture my Float is set to 111111111111 then when I get the double value the number becomes 111111110656

Emax
  • 1,343
  • 2
  • 19
  • 30
rpascal
  • 723
  • 1
  • 8
  • 25
  • 1
    Don't post pictures of code – Michael Mar 08 '19 at 13:42
  • 1
    @Michael seeing as the picture shows the values he's talking about, which we wouldn't be able to see if he just posted code, I don't think it's such a problem in this case. – Stultuske Mar 08 '19 at 13:42
  • https://floating-point-gui.de/ – Tim Mar 08 '19 at 13:42
  • 1
    @Stultuske You can add that as a comment along side the code. It would take like 30 seconds to transcribe. – Michael Mar 08 '19 at 13:45
  • A float can hold 6 to 9 digits as precision. So indeed 1111_1111_1111f == 1111_1111_0656f == 1.1111_1111E11. _One should not believe everything one reads._ – Joop Eggen Mar 08 '19 at 13:50

0 Answers0