+ 2
Why this happens?
When I add floats and get the sum of them, the result is inaccurate. https://code.sololearn.com/cz0swy0QVg0X/?ref=app
7 Answers
+ 1
What output did you expect actually?
+ 1
As I understand it, floating point calculation accuracy is a tricky problem, maybe someone can explain about that better.
Although this may not be a definite solution (nor even work), you can try to use double in place of float.
+ 1
B.virus
Write this after for loop,
if you mean to truncate after 72.87000
printf("%.5f\n",sum);
+ 1
U can take double in place of float
0
I writed printf outside the loop, and the result is 72.87003.
0
72.87000 is what I expect