0

According to this float converter(https://www.h-schmidt.net/FloatConverter/IEEE754.html), 0.1 is actually stored binary as 00111101110011001100110011001101.....(infinite). Its decimal representation then is something like 0.100000001490116119384765625. How Java,for example, when we store a float like 0.1 and we print it, is actually represented as "0.1" and not the real value stored like "0.100000001490116119384765625"?

Thanks

9
  • 2
    Rounding, most likely. Commented Feb 4, 2019 at 19:39
  • @RobertHarvey: This question does not seeking debugging help or ask “why isn’t this code working’, so closing it on that basis is inappropriate. Commented Feb 5, 2019 at 0:23
  • 1
    Java does not represent .1 as .1. When “0.1” is read in source text or from a string converted to a double, the result is 0.1000000000000000055511151231257827021181583404541015625. When printed with default formatting, this is shown as “0.1” because Java’s default formatting is to convert the actual number to the shortest decimal numeral such that converting the decimal numeral back to double yields the double value. This creates an illusion that the double is .1, but, actually, .1 is just close to the double value. (Shortest by number of significant digits, not string length.) Commented Feb 5, 2019 at 0:27
  • @EricPostpischil: Which close reason do you prefer? Commented Feb 5, 2019 at 1:16
  • @RobertHarvey: it is a valid question and has an answer, so it should either be opened and answered or closed as a duplicate if a proper one is identified. Commented Feb 5, 2019 at 1:17

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.