How do I instruct python that it should consider only 2 decimal spaces?
x = -1.7999999999999998 + 0.20000000000000018 + 0.20000000000000018 - 0.7999999999999998 + 2.2
print('%.02f' % x)
0.00
I have manually adjusted values as below. But is there any way to automate this?
y = -1.79 + 0.20 + 0.20 - 0.79 + 2.2
print('%.02f' % y)
Update: I am trying to calculate sum of mean differences. I am not getting expected values.
y = [1,3,3,2,5]
avg = sum(y) / len(y)
mylist = list()
for i in y:
mylist.append(i - avg)
sum(mylist)