I appreciate the comments and references but I am still not understanding how doubles are stored. I do understand how floats work and thought doubles did the same but used another byte for greater precision. In a nut shell here's what doesn't make sense to me:
double a = 5.01 is stored as 5.01 how is it able to do that?
since .1 can't be represented in binary?
This question is NOT a duplicate of the question cited. In the first case .01 is being stored as .0099999999787 and in the second case .01 is being stored as .01000000000000
The comment that println sometime rounds is plausible but calculations are being treated as if the value is indeed .0100000000000
I have the following example that I don't understand:
double a = 6;
double b = 5.99;
double c = .99;
System.out.println((a-b) + " " + (a-c));
why is a - b = .0099999999999787 (which seems correct)
but a - c = 5.01 (which seems incorrect)
shouldn't a - c = 5.0099999999787 ?