round probleme under python 2.0

Kalle Svensson kalle at gnupung.net
Sat May 19 12:30:53 EDT 2001


Sez William Famy:
> I have a problem with python 2.0 under gnu linux debian/sid.
> round seem not working well. any idea to solve the problem?

It works.  The only thing changed is how it's printed.  Floats are now by
default repr'd more exactly.  Search googlegroups for floating point, and
you'll see that you're not the first one to discover this.

Also:
http://www.python.org/cgi-bin/moinmoin/FrequentlyAskedQuestions#line24

> _________________
> Under Python 2.0
> 
> >>> b
> 2.8465416541454847
> >>> [v,b]
> [31.665164691616152, 2.8465416541454847]
> >>> [round(v,2),round(b,2)]
> [31.670000000000002, 2.8500000000000001]
> >>> round(v,2)
> 31.670000000000002

These are correct.  Try
>>> print round(v, 2)
or
>>> str(round(v, 2))

Peace,
  Kalle
-- 
Email: kalle at gnupung.net     | You can tune a filesystem, but you
Web: http://www.gnupung.net/ | can't tune a fish. -- man tunefs(8)
PGP fingerprint: 0C56 B171 8159 327F 1824 F5DE 74D7 80D7 BF3B B1DD
 [ Not signed due to lossage.  Blame Microsoft Outlook Express. ]




More information about the Python-list mailing list