Search code examples
pythonfloating-pointnumbersscientific-notation

How to convert a negative exponential number into a decimal number in Python?


I'm having hard time converting the following numbers for example:

-1.9443404027234424e+46
-1.9443404027234425e+36

in a format without the scientific notation (AKA a float like 0.04256 for example).


Solution

  • You can use the :f format specifier:

    >>> print("{:.0f}".format(-1.9443404027234424e+46))
    -19443404027234423757622069004479676797119627264
    

    Note that the result may not end with 46 zeros because of floating point precision.