0

I have below program:

double tax = 180.09;
double gTotal = 277.08;

double total = tax + gTotal;

System.out.println(total);

After execution it outputs 457.16999999999996.

After Google search I found that one of the cause for this behavior is that there may be no precise binary representation of the fraction part.

To verify that I tried below:

double dNum = 457.17;
System.out.println(dNum);

It gave correct output as 457.17. In this case, why it is not printing 457.16999999999996.

Vinod
  • 1,036
  • 2
  • 16
  • 32

0 Answers0