[Tutor] round() errors
Kalle Svensson
kalle@gnupung.net
Wed, 12 Sep 2001 22:54:24 +0200
[Christian Mascher]
> I don't understand some response from the round()-function.
>
> >>> round(1.4783321399,2)
> 1.48
> >>> round(1.95583,2) # this is the ratio of EURO to DM
> 1.96
>
> so far, so good, but ...
>
> >>> round(10*1.95583,2)
> 19.559999999999999
> >>> round(20*1.95583,2)
> 39.119999999999997
> >>> a=20*1.95583
> >>> a
> 39.116599999999998
> >>> round(a,2)
> 39.119999999999997
>
> >>> print '%.2f' %a
> 39.12
> >>>
>
> why can't round() do the same? Is there any reason?
>>> round(20*1.95583,2)
39.119999999999997
>>> print round(20*1.95583,2)
39.12
>>> repr(round(20*1.95583,2))
'39.119999999999997'
>>> str(round(20*1.95583,2))
'39.12'
>>>
Peace,
Kalle
--
[ kalle@gnupung.net ][ Thought control, brought to you by the WIPO! ]
[ http://gnupung.net/ ][ http://anti-dmca.org/ http://eurorights.org/ ]