Engineering numerical format PEP discussion

Steven D'Aprano steve at
Mon Apr 26 06:29:37 CEST 2010

On Sun, 25 Apr 2010 20:36:22 -0700, Keith wrote:

> I am considering writing a PEP for the inclusion of an engineering
> format specifier, and would appreciate input from others.
> For instance, no one talks about 4.7e-5F, as they would rather see 47e-6
> (micro).  Instead of 2.2e-2, engineers need to see 22.0e-3 (milli).

I'd be cautious about making claims about "no one", because not everyone 
wants to see engineering notation. You may recall that the other common 
display format on scientific calculators is Scientific Notation, which 
*does* display 2.2e-2.

> After many months of using my EFloat class extensively with lots of apps
> dealing with embedded engineering tasks, it dawns on me that what we
> really need is simply a new format specifier.
> I am thinking that if we simply added something like %n (for eNgineer)
> to the list of format specifiers that we could make life easier for
> engineers:

I for one don't like %n. I already write %n for integer, at least now I 
get an error immediately instead of code that silently does the wrong 
thing. But I don't have a better idea of what letter to use.

However, for good or ill the general consensus among the Python language 
developers is that % formatting is to be discouraged in favour of the 
format() method. For this reason, I expect that there will be zero (or 
negative) interest in extending the list of % format specifiers. But 
there may be some interest in adding a specifier to format().

It may be worth mentioning in the PEP that Decimals already have a method 
for converting to engineering notation, to_eng_string.


More information about the Python-list mailing list