1
double amount1 = 2.15;
double amount2 = 1.10;
System.out.println(amount1 - amount2);

-------

1.0499999999999998

Why above code produces 1.0499999999999998

user8355591
  • 181
  • 1
  • 10
  • Try out `0.1 + 0.2` should return smth like `0.30000004`. Its because how floating point numbers and binary work. Maybe this is interesting for you: https://www.youtube.com/watch?v=PZRI1IfStY0&t=230s – René Jul 22 '20 at 05:44
  • https://floating-point-gui.de/ –  Jul 22 '20 at 06:07

0 Answers0