What result will I get if from 2.49 I take 0.17 ? 2.32 of course !!! But why the Java return 2.3200000000000003 ?
This is my easy code:
    double x = 2.49;
    double y = 0.17;
    System.out.println(x - y);
How can I get the right result ?
What result will I get if from 2.49 I take 0.17 ? 2.32 of course !!! But why the Java return 2.3200000000000003 ?
This is my easy code:
    double x = 2.49;
    double y = 0.17;
    System.out.println(x - y);
How can I get the right result ?
 
    
    You can use this :
  double d = x-y;
  DecimalFormat f = new DecimalFormat("##.00");
  System.out.println(f.format(d));
