Remove leading 0 in exponential format in python

I have the following code in Python 3.1

"{0:.6E}".format(9.0387681E-8)

      

Which gives line 9.038768E-08, but I want line 9.038768E-8 with the leading 0 E-08 removed. How should I do it?

+3


source to share


1 answer


you could do something like this

"{0:.6E}".format(9.0387681E-8).replace("E-0", "E-")

      

or better, since J. Bernardo suggests



format(9.0387681E-8, '.6E').replace("E-0", "E-")

      

You need to substitute for E+0

if you have large numbers

+2


source







All Articles