round() wrong in Python 2.4?

Sion Arrowsmith siona at chiark.greenend.org.uk
Tue Sep 13 11:36:51 EDT 2005


Nils Grimsmo <nils.grimsmo at gmail.com> wrote:
>Why did round() change in Python 2.4?
>
>$ python2.3
>Python 2.3.5 (#2, Jun 19 2005, 13:28:00)
>[GCC 3.3.6 (Debian 1:3.3.6-6)] on linux2
>>>> round(0.0225, 3)
>0.023
>>>> "%.3f" % round(0.0225, 3)
>'0.023'
>>>>
>$ python2.4
>Python 2.4.1 (#2, Jul 12 2005, 09:22:25)
>[GCC 4.0.1 (Debian 4.0.1-1)] on linux2
>>>> round(0.0225, 3)
>0.021999999999999999
>>>> "%.3f" % round(0.0225, 3)
>'0.022'
>>>>
>
>(Is this due to the different GCC used?)

That would look like a good guess to me:

$ python
Python 2.4.1 (#2, May  5 2005, 11:32:06)
[GCC 3.3.5 (Debian 1:3.3.5-12)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> round(0.0225, 3)
0.023
>>> "%.3f" % round(0.0225, 3)
'0.023'
>>>

Is that python2.4 of yours from the python2.4 package or one
you compiled up yourself?

-- 
\S -- siona at chiark.greenend.org.uk -- http://www.chaos.org.uk/~sion/
  ___  |  "Frankly I have no feelings towards penguins one way or the other"
  \X/  |    -- Arthur C. Clarke
   her nu becomeþ se bera eadward ofdun hlæddre heafdes bæce bump bump bump



More information about the Python-list mailing list