[EMAIL PROTECTED] wrote: > On Mar 14, 1:14 pm, Darren Dale <[EMAIL PROTECTED]> 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? > > > Do you also consider this to be too inefficient? > > > import math > > for exponent in xrange(-10, 11): > flt = 1.23 * math.pow(10, exponent) > l = math.log10(flt) > if l < 0: > l = l - 3 > p3 = int(l / 3) * 3 > multiplier = flt / pow(10, p3) > print '%e => %fe%d' % (flt, multiplier, p3) >
That's a good suggestion. It's probably fast enough. I was hoping that something like '%n'%my_number already existed. -- http://mail.python.org/mailman/listinfo/python-list