round(22.47,2) gives 22.469999999999999?

Tim Roberts timr at probo.com
Fri Aug 8 00:06:18 EDT 2003


Daniel Klein <danielk at aracnet.com> wrote:

>Eric van Riet Paap <eric at vanrietpaap.com> wrote:
>
>>On python2.1.3, python2.2.1 and python2.2.3 round(22.47,2) gives 
>>22.469999999999999 . Does anyone know if this is a bug or some weird, yet 
>>unexpected, behaviour?
>
>Wouldn't
>
>int(22.47 + .5)
>
>get you to where you want to go?

No, you didn't read the assignment.  :)

round(22.47,2) gives roughly 22.47.  int(22.47+.5) gives 22.  VERY
different numbers.
-- 
- Tim Roberts, timr at probo.com
  Providenza & Boekelheide, Inc.




More information about the Python-list mailing list