Python rounding issue
问题 I have come across a very strange issue in python. (Using python 2.4.x) In windows: >>> a = 2292.5 >>> print '%.0f' % a 2293 But in Solaris: >>> a = 2292.5 >>> print '%.0f' % a 2292 But this is the same in both windows and solaris: >>> a = 1.5 >>> print '%.0f' % a 2 Can someone explain this behavior? I'm guessing it's platform dependent on the way that python was compiled? 回答1: The function ultimately in charge of performing that formatting is PyOS_snprintf (see the sources). As you surmise,