I've been working on some code and hade to write this for loop:
for(double i = -1; i <= 1; i += 0.1) {
cout << i << "\n";
}
The weird thing is that when I run the code above, I get the following values:
-1
-0.9
-0.8
-0.7
-0.6
-0.5
-0.4
-0.3
-0.2
-0.1
-1.38778e-16
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
1
At the middle, instead of getting 0, I get this number: -1.38778e-16. Can you please explain why this is happening and how I can fix this?