Why does this happen when rounding floating numbers in Python?
问题 I am looking into rounding floating point numbers in Python and the following behavior seems quite strange: Code : a = 203.25 print '%.2f'%(a/10.) print '%.2f'%(round(a/10., 2)) print '%.2f'%(0.1*a) Output : 20.32 20.32 20.33 Why does the first and especially the second case fail? 回答1: http://en.wikipedia.org/wiki/Rounding#Round_half_to_even Round half to even A tie-breaking rule that is less biased is round half to even , namely: If the fraction of y is 0.5, then q is the even integer