Floating point -> string conversions
John Fouhy
jfouhy at paradise.net.nz
Sun Nov 7 23:02:36 EST 2004
Can someone explain these differences?
>>> from math import pi
>>> pi
3.1415926535897931
>>> type(pi)
<type 'float'>
>>> repr(pi)
'3.1415926535897931'
>>> str(pi)
'3.14159265359'
>>> '%f' % pi
'3.141593'
>>> '%.16f' % pi
'3.1415926535897931'
Why do the string and default floating point representations get rounded?
(and is this documented anywhere?)
--
John.
More information about the Python-list
mailing list