centenial
09-28-2009, 04:19 AM
I'm confused as to the precision of this output:
double change;
change = 45.69;
change -= 40;
System.out.println(change);
This code outputs 5.689999999999998. I would expect it to output 5.69.
Could someone explain to me why this is happening, and what I need to do for it to retain precision of the correct number?
Thanks!
double change;
change = 45.69;
change -= 40;
System.out.println(change);
This code outputs 5.689999999999998. I would expect it to output 5.69.
Could someone explain to me why this is happening, and what I need to do for it to retain precision of the correct number?
Thanks!