Output: Number of digits in exponent?

Jens Bloch Helmers Jens.DOTBloch.DOTHelmers at ATdnv.com
Tue Dec 6 12:29:51 CET 2005

How can I control the number of digits in the exponent when writing
floats to a file? It seems that Python2.4.2(winXP) prints three digits anyway.

>>> print 1.0e50
>>> print '%e' % (1.0e50)

I would prefer two digits in the exponent. Usually 3 digits is not a
problem, except for waisted disk space in 99.999999% of all practical

But this time I have to write an interface file to a program written
in an other programming language, and the output format requires a fix
fortran format with 2 digits in the exponent.

Can this be done in Python? Speed is an issue so I don't like the
idea of rolling my own output function.

It should be possible to do:
>>> print '%12.5.2e' % (1.0e50)

Thanks for any help!

More information about the Python-list mailing list