2
Answers

problem with data type

k

k

15y
3.8k
1

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)