According to Banker's rounding, ties goes to even, for example,
round(1.25,1) -> 1.2 round(1.35,1) -> 1.4
But, in case of following rounding,
round(1.15,1) -> 1.1
It should be 1.2, why it is 1.1
Can anyone help.
According to Banker's rounding, ties goes to even, for example,
round(1.25,1) -> 1.2 round(1.35,1) -> 1.4
But, in case of following rounding,
round(1.15,1) -> 1.1
It should be 1.2, why it is 1.1
Can anyone help.
float implementation in python do not allow to save any fraction, so certain are saved as approximations, see decimal built-in module docs for further discussion. python does show it as 1.15 but in reality it is other (close) number which can be saved as float, consider following
print(1.15+1.15+1.15==3.45) # False
print(1.15+1.15+1.15) # 3.4499999999999997
You might use decimal.Decimal to prevent float-related problems as follows
import decimal
approx = round(decimal.Decimal("1.15"),1)
print(approx) # 1.2
Note that you should use str as decimal.Decimal not float.