Search code examples
pythonfloating-pointexponential

Displaying 6.5235375356299998e-07 without exponential notation


I have to convert exponential strings, like 6.5235375356299998e-07, to a float value, and display the result of my computation like 0.00000065235... How can I do this in a Python program?


Solution

  • 6.5235375356299998e-07 is a perfectly legal float even if there is an e in it. You can do the whole calculation with it:

    >>> 6.5235375356299998e-07 * 10000000
    6.5235375356300001
    
    >>> 6.5235375356299998e-07 + 10000000
    10000000.000000652
    

    In the second case, many digits will disappear because of the precision of a python's float.

    If you need the string representation without e, try this:

    >>> '{0:.20f}'.format(6.5235375356299998e-07)
    '0.00000065235375356300'
    

    but it will become a string and you won't be able to do any calculus with it any more.