I have the following code in Python 3.1
JavaScript
x
2
1
"{0:.6E}".format(9.0387681E-8)
2
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?
Advertisement
Answer
you could do something like this
JavaScript
1
2
1
"{0:.6E}".format(9.0387681E-8).replace("E-0", "E-")
2
or better as JBernardo suggests
JavaScript
1
2
1
format(9.0387681E-8, '.6E').replace("E-0", "E-")
2
You need to do a replace for E+0
as well if you have big numbers