5

I have the following code in Python 3.1

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

Which gives a string of 9.038768E-08, but I want the string 9.038768E-8 with the leading 0 of E-08 removed. How should I go about this?

wjandrea
  • 28,235
  • 9
  • 60
  • 81
Michael
  • 1,321
  • 1
  • 13
  • 27

1 Answers1

3

you could do something like this

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

or better as JBernardo suggests

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

You need to do a replace for E+0 as well if you have big numbers

John La Rooy
  • 295,403
  • 53
  • 369
  • 502