Print Numbers In Terms Of Engineering Units In Python
Possible Duplicate: Print number in engineering format How do I print numbers in scientific notation with powers that are multiples of 3? For example: 1.5e4 --> 15e3 1.2
Solution 1:
It appears there isn't such a feature yet (at least in Python 2.7), see: http://bugs.python.org/issue8060 On the page http://bytes.com/topic/python/answers/616948-string-formatting-engineering-notation I found the following solution (which I personally don't like that much, but seems to work):
import mathfor 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)
Just adapt it according to your needs.
EDIT: Please look here, too Print number in engineering format
Post a Comment for "Print Numbers In Terms Of Engineering Units In Python"