So the question is in the title. Here are some more details:
code:
a=0.975
print(round(a,2))
print(round(a*100)/100)
a=-0.975
print(round(a,2))
print(round(a*100)/100)
a=1.975
print(round(a,2))
print(round(a*100)/100)
a=-1.975
print(round(a,2))
print(round(a*100)/100)
The printed output is:
0.97
0.98
-0.97
-0.98
1.98
1.98
-1.98
-1.98
I guess there is something going on with floating point error and how round()
handles float numbers?
It seems to be the case between -1 and 1. Probably round()
is shifting the floating point and creating a number with more digits after the 5?
Can someone explain, whether there is a way to avoid this?