Engineering numerical format PEP discussion

Chris Rebert clp2 at rebertia.com
Mon Apr 26 06:02:45 CEST 2010


On Sun, Apr 25, 2010 at 8:36 PM, Keith <keith.brafford at gmail.com> wrote:
> I am considering writing a PEP for the inclusion of an engineering
> format specifier, and would appreciate input from others.
>
> Background (for those who don't already know about engineering
> notation):
>
> Engineering notation (EN) is type of floating point representation.
> The idea with EN is that the powers of 10 are all multiples of 3,
> which correspond to the familiar Greek unit prefixes that engineers
> use when describing the different sizes of all sorts of real-world
> devices and phenomena:
>
> 1e-12 == pico
> 1e-9  == nano
> 1e-6  == micro
> 1e-3  == milli
> 1e+3  == kilo
> 1e+6  == mega
> 1e+9  == giga
>
> When people are talking about Ohms, Farads, Henries, Hz, and many
> others, they routinely have to normalize to EN.  Fancy calculators
> from HP and TI routinely allow the users to go into engineering mode,
> but mysteriously things like C, Python, Excel, etc. don't
>
> 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).
<snip>
> There are places on the web where I've read that people have to work
> their butts off trying to "trick" Excel or OpenOffice to do
> engineering notation, or there is some work-around that is purported
> to work if you use the right version of the spreadsheet.

Relevant related information:
The Decimal datatype supports engineering format directly:
http://docs.python.org/library/decimal.html#decimal.Decimal.to_eng_string

Cheers,
Chris
--
http://blog.rebertia.com



More information about the Python-list mailing list