0

okay, now I do understand why

double paymentSum;
double a = ((paymentSum/100.0)-1.54);

returns a = 0.45999999999999996 and not a=0.46

here my question would be how to make the result a=0.46 from the existing result

also paymentSum is an input made my user, let's say paymentSum=200

  • Also check out: http://stackoverflow.com/questions/1661273/floating-point-arithmetic-not-producing-exact-results – AntonH Feb 23 '16 at 18:55
  • When you use decimals, you need to consider appropriate rounding. You can either use BigDecimal which can help you or you need to round the result e.g. when you print it. – Peter Lawrey Feb 23 '16 at 18:58
  • I haven't covered BigDecimal part of java yet. Perks of being new programmer I guess. But I tried learning BigDecimal from other answers here on my own and I have no idea what I just read about BigDecimal. Will have to wait for my professor. – tryingToLearnC Feb 23 '16 at 19:08
  • You can round when printing, but using "floating point" numbers (like `double`) is virtually always a huge mistake when dealing with things like money. – John Hascall Feb 23 '16 at 20:06

0 Answers0