string formatting - How to force exponential number to be print with leading dot in python? -
i trying print exponential number in python need number start dot. :
>>>print( "{:+???}".format(1.2345678) ) +.1234e+01
if multiply number 10 , format number scientific notation, have correct exponent coma misplaced. fortunately, know there 1 character sign , 1 digit before coma. can do
def format_exponential_with_leading_dot(n): = "{:+e}".format(n * 10) return a[0] + '.' + a[1] + a[3:] >>> print format_exponential_with_leading_dot(1.2345678) +.1234568e+01
Comments
Post a Comment