Number of digits in exponent

There is a no way to control that, best way is to write a function for this e.g. def eformat(f, prec, exp_digits): s = “%.*e”%(prec, f) mantissa, exp = s.split(‘e’) # add 1 to digits as 1 is taken by sign +/- return “%se%+0*d”%(mantissa, exp_digits+1, int(exp)) print eformat(0.0000870927939438012, 14, 3) print eformat(1.0000870927939438012e5, 14, 3) print … Read more

Converting unit abbreviations to numbers

So you want to translate SI unit abbreviations (‘K’,’M’,…) into exponents, and thus numerical powers-of-ten. Given that all units are single-letter, and the exponents are uniformly-spaced powers of 10**3, here’s working code that handles ‘Kilo’…’Yotta’, and any future exponents: > 10 ** (3*as.integer(regexpr(‘T’, ‘KMGTPEY’))) [1] 1e+12 Then just multiply that power-of-ten by the decimal value … Read more