Entry
How can I convert a floating point number to a string?
Mar 1st, 2000 22:06
Nathan Wallace, unknown unknown, Gerrit Holl, Carel Fellinger
>>> str(1.5)
'1.5'
You can use the builtin 'str' function if you want to convert _anything_
to a string: not only integers, lists, and dictionairies, but also file
objects and class instances. Please read the documentation for more
information.
If more control over the layout is needed you might use the "%" trickery
like:
>>> '%5.2f' % 123.4567
123.45
>>> '%5.2e' % 123.4567
1.23e+02