Engineering numerical format PEP discussion

MRAB python at mrabarnett.plus.com
Mon Apr 26 20:47:15 EDT 2010


Mark Dickinson wrote:
> On Apr 26, 4:36 am, Keith <keith.braff... at gmail.com> wrote:
>> I am considering writing a PEP for the inclusion of an engineering
>> format specifier, and would appreciate input from others.
> 
>> [...]
> 
>> 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:
>>
>> ("%n" % 12345)  == "12.345e+03"
>> ("%n" %  1234)  == "1.234e+03"
>> ("%n" %   123)  == "123e+00"
>> ("%n" % 1.2345e-5)  == "12.345e+06"
> 
> I don't think there's much chance of getting changes to old-style
> string formatting accepted;  you might be better off aiming at the new-
> style string formatting.  (And there, the 'n' modifier is already
> taken for internationalization, so you'd have to find something
> different. :)
> 
"e" is already used, "n" is already used, "g" is already used, etc

"t" for "powers of a thousand", perhaps? (Or "m"?)



More information about the Python-list mailing list