Python Numpy – Print Scientific Notation Numbers in Same Scale

numpypython

I want to print scientific notation number with same scale in python. For example I have different numbers (1e-6, 3e-7, 5e-7, 4e-8)so now I want to print all these numbers with e-6 notation (1e-6, 0.3e-6, 0.5e-6, 0.04e-6). So how can I print it?

Thanks

Best Answer

Mathematically, tacking on e-6 is the same as multiplying by 1e-6, right?

So, you've got a number x, and you want to know what y to use such that y * 1e-6 == x.

So, just multiply by 1e6, render that in non-exponential format, then tack on e-6 as a string:

def e6(x):
  return '%fe-6' % (1e6 * x,)
Related Question