Converting exponential numbers to strings.

Emile van Sebille emile at fenx.com
Tue Nov 6 08:52:24 EST 2001


"steve" <steve at clublinux.org> wrote in message
news:3BE7E301.3E5EDDF1 at clublinux.org...
>
> One more question about string processing.  I've written a small report
> formating routine that prints everything as strings.  The reason for
> this is that I want to be able to add commas, floating dollar signs,
> etc. to the report and printing everything as a string seemed to be the
> easiest way to perform such tasks.
>
> I run into the same problem when trying to process the string from
> printing when I use the str() function.  Is there another way to convert
> a number to a string that will return the number in a non-exponential
> format?
>
> (e.g. return .000085 instead of 8.5e-5?)
>
> Thanks again for your help,
> Steve

The % operator works well for this kind of output.

>>> print '%7.4f' % (.0085,)
 0.0085
>>> print '%9.6f' % (.0085,)
 0.008500
>>>


--

Emile van Sebille
emile at fenx.com

---------




More information about the Python-list mailing list