[python-win32] Bug or Feature ??? working with floats under win32
Jorgensen, Jens
jens.jorgensen@tallan.com
Tue, 07 Aug 2001 15:06:02 -0500
I get the same result in Windows 2000 Pro with ActiveState Python 2.1:
>>> sys.version
'2.1 (#15, Jun 18 2001, 21:42:28) [MSC 32 bit (Intel)]'
I tend to think this is not a bug though. Remember that in the floating
point representation the decimal part is represented in base 2 so 2/10
is not actually possible. This is as close as it can get. The difference
will be due to how str(<double>) is implemented on the two systems which
is probably just done using printf("%f", ld) or similar. I'll bet that
if you try:
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.
Ulrich Eck wrote:
> Hi out there,
>
>
>
> I have this problem:
>
>
>
> >>> f = 4.23452345
> >>> round(f,1)
> 4.2000000000000002
>
>
>
> under win32 using:
>
>
>
> PythonWin 2.1 (#15, Apr 16 2001, 18:25:49) [MSC 32 bit (Intel)] on win32.
> Portions Copyright 1994-2001 Mark Hammond ( MarkH@ActiveState.com
> <mailto:MarkH@ActiveState.com> ) - see 'Help/About PythonWin' for
> further copyright information.
>
> this version ..
>
>
>
> has anyone had this as well ..
>
>
>
> same works fine using python2.1 under linux:
>
> >>> f = 4.112345234
> >>> round(f,1)
> 4.1
>
>
>
> thanks for your comments
>
>
>
> Ulrich Eck
>
> net-labs
>
--
Jens B. Jorgensen
jens.jorgensen@tallan.com