string formatting: engineering notation
grante at visi.com
Wed Mar 14 22:10:41 CET 2007
On 2007-03-14, Steve Holden <steve at holdenweb.com> wrote:
> Darren Dale wrote:
>> Does anyone know if it is possible to represent a number as a string with
>> engineering notation (like scientific notation, but with 10 raised to
>> multiples of 3: 120e3, 12e-6, etc.). I know this is possible with the
>> decimal.Decimal class, but repeatedly instantiating Decimals is inefficient
>> for my application (matplotlib plotting library). If it is not currently
>> possible, do you think the python devs would be receptive to including
>> support for engineering notation in future releases?
> How close is this:
> >>> "%.3e" % 3.14159
Not close at all. It should be "3.14159"
>>> "%.3e" % 31.4159
should be 31.4159
>>> "%.3e" % 314.159
should be 314.159
>>> "%.3e" % 31415.9
should be 31.4159e3
Grant Edwards grante Yow! LOU GRANT froze
at my ASSETS!!
More information about the Python-list