How to write string (float) to file?

Rainer Deyke root at rainerdeyke.com
Wed Aug 29 12:04:23 EDT 2001


"Grant Edwards" <grante at visi.com> wrote in message
news:slrn9ops86.ks3.grante at grante.comtrol.com...
> In article <9ZOi7.53225$c8.23251519 at news1.denver1.co.home.com>, Rainer
Deyke wrote:
> ><gbreed at cix.compulink.co.uk> wrote in message
> > news:9mfqmi$ko4$1 at thorium.cix.co.uk...
> >> c = '%.2f'%(float(a)/b)
> >
> > That's unreliable.  Use this instead:
>
> After reading a handful of follow-ups, I'm still curious what
> you mean when you say that's unreliable.

>>> def foo(a, b): return '%.2f' % (float(a)/b)
...
>>> foo(1, 200)
'0.01'
>>> foo(3, 200)
'0.01'
>>> foo(5, 200)
'0.03'
>>> foo(10000000000000000000000000000000000000000l, 2)
'5000000000000000200000000000000000000000.00'


--
Rainer Deyke (root at rainerdeyke.com)
Shareware computer games           -           http://rainerdeyke.com
"In ihren Reihen zu stehen heisst unter Feinden zu kaempfen" - Abigor





More information about the Python-list mailing list