How to write string (float) to file?

Grant Edwards grante at
Wed Aug 29 23:10:19 CEST 2001

In article <1Vbj7.71653$54.3810366 at>, Steve Holden wrote:

> "Rainer Deyke" <root at> wrote in message
> news:G89j7.54140$c8.24141594 at
> [ ... ]
>> > >>>> foo(10000000000000000000000000000000000000000l, 2)
>> > > '5000000000000000200000000000000000000000.00'
>>                      ^
>> Not just incorrect, but the incorrect digit is right in the middle of the
>> number, not in the least significant place.
> Well by my count it occurs in the seventeenth decimal place,
> which given the precision on floats is about what you ought to
> expect. Clearly if you need to deal with numbers of arbitrary
> precision you are going to *have* to represent them as longs
> and keep a scaling factor (or use some other similar
> technique).
> However, I would say that for most normal accounting purposes
> (i.e. numbers up to the tens of millions, significant to 2 DP,
> or ten significant figures) floating point numbers will be
> perfectly satisfactory *provided roundoff error is controlled
> at each step*. [This will also be good enough for the OMB,
> since they seem to round everything to the nearest million
> anyway :-)]

For accounting stuff I think you'd be far better off using
integer math in cents or mils or something like that.  Or
find/write a BCD floating point package.

But, I am not an accountant, and my head almost exploded the
time somebody explained what "good will" meant...

Grant Edwards                   grante             Yow!  My mind is making
                                  at               ashtrays in Dayton....

More information about the Python-list mailing list