float problem

Peter Maas fpetermaas at netscape.net
Thu Mar 18 12:01:18 CET 2004

Tomasz Stochmal schrieb:
> The problem is that when I call float('713566671863.6850') I get
> 713566671863.68506 - when rounding to 4 becomes 713566671863.6851
> Output becomes 7135666718636851 but it should be 7135666718636850 
> Last digit is 1 but should be 0 which is wrong !
> How do I do it ?

I think it' impossible because you operate at the border of the
IEEE754 float8 precision.

struct.pack("d", 713566671863.68506)
struct.pack("d", 713566671863.6851)

will yield the same result:

which means that the two float literals are represented by the
same 64bit string. I you want arbitrary precision use Python's
long integers.

Mit freundlichen Gruessen,

Peter Maas

Peter Maas, M+R Infosysteme, D-52070 Aachen, Hubert-Wienen-Str. 24
Tel +49-241-93878-0 Fax +49-241-93878-20 eMail peter.maas at mplusr.de

More information about the Python-list mailing list