[python-win32] working with floats

John Kochmar kochmar@psc.edu
Tue, 07 Aug 2001 16:54:57 -0400


|>
|> import struct
|> struct.pack('f', (round(4,23452345, 1)))
|>
|> on both boxes you'll get the same thing on each. I don' t think that the
|> docs for str() explicitly say exactly how double precision floats will
|> be formatted so this is really neither bug nor feature just ambiguity.
|>
|
|ok the problem is not the platform but the actual float (see below)
...

The problem might not be the platform as much as the version of Python...

imp:~ python
Python 1.5.2 (#1, Mar  3 2001, 01:35:43)  [GCC 2.96 20000731 (Red Hat Linux 
7.1 2 on linux-i386
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
>>> f = 4.112345234
>>> round(f,1)
4.1
>>> 

imp:~ python2
Python 2.1 (#1, Apr 21 2001, 18:56:55) 
[GCC 2.96 20000731 (Red Hat Linux 7.0)] on linux2
Type "copyright", "credits" or "license" for more information.
>>> f = 4.112345234
>>> round(f,1)
4.0999999999999996
>>> 

Both were done on my Linux box moments ago.

John

-- 

John Kochmar						kochmar@psc.edu
PSC Advanced Systems					MI 409F, x8-6509
http://www.psc.edu/~kochmar