From: W. Trevor King Date: Wed, 11 Aug 2010 13:58:09 +0000 (-0400) Subject: Allow fallback to XeX notation for efor extreme powers in ppSI X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=6c5cbf09021e1571f7128ad7b782e5b13d79a8e1;p=hooke.git Allow fallback to XeX notation for efor extreme powers in ppSI --- diff --git a/hooke/util/si.py b/hooke/util/si.py index ac3e633..14d9010 100644 --- a/hooke/util/si.py +++ b/hooke/util/si.py @@ -127,7 +127,11 @@ def ppSI(value, unit='', decimals=None, power=None, pad=False): # 1 for ' ', 1 for '-', 3 for number, 1 for '.', and decimals. pad = 6 + decimals format = lambda n: '%*.*f' % (pad, decimals, n) - return '%s %s%s' % (format(value / pow(10,power)), PREFIX[power], unit) + try: + prefix = ' '+PREFIX[power] + except KeyError: + prefix = 'e%d ' % power + return '%s%s%s' % (format(value / pow(10,power)), prefix, unit) def get_power(value):