I write the following code with a for loop.
double d1 = 0;
for (int i = 1; i <= 8; i++) {
d1 += 0.1;
}
System.out.println(d1);
The output is 0.7999999999999999. It is supposed to be 0.8. but I don't understand what causes it and how to avoid the rounding problem in the future.