k

k

  • NA
  • 25
  • 0

problem with data type

Dec 3 2008 1:02 PM

double temp = 0;
for (int i = 0; i < 20; i++)
         temp += 0.05;

I thought the value of temp must be 1.0. But when I debug my program, I saw the value of temp was 1.0000000000000002.
I don't know why temp has a value like that. Anyone can explain it for me? I need to use the true value of temp (1.0) to compare with 1.


Answers (2)