[Python] How to format a floating point number in engineering notation with zero before...

Discussão em 'Python' iniciado por Stack, Maio 19, 2025.

  1. Stack

    Stack Membro Participativo

    I am trying to output the data from Python so that the output format matches the output from a FORTRAN code.

    When using E format specifier in Python, I get a non-zero leading digit before the decimal dot, i.e.

    >>> print("%13.5E" % 3.1415926)
    3.14159E+00


    This corresponds to ES data edit descriptor in FORTRAN.

    Is it possible to instruct Python string formatter to output instead the number with a zero as the first leading digit, i.e.

    0.31415E+01


    This behavior matches the behavior of E data edit descriptor in FORTRAN.

    Continue reading...

Compartilhe esta Página