[Python] Print in scientific format with powers of ten being only multiples of 3

Discussão em 'Python' iniciado por Stack, Abril 28, 2025.

  1. Stack

    Stack Membro Participativo

    I haven't found a way to only get exponents which are multiples of 3, when displaying numbers in the scientific format. Neither did I succeed writing a simple custom formatting function.

    Here is a quick example:
    Normal behaviour using scientific notation with pythons .format():

    numbers = [1.2e-2, 1.3e-3, 1.5e5, 1.6e6]

    for n in numbers:
    print("{:.E}".format(n))


    >>> 1.20E-02
    1.30E-03
    1.50E+05
    1.60E+06


    I, however, need the following output:

    >>> 12.00E-03
    1.30E-03
    15.00E+06
    1.60E+06


    Does anyone know a convenient way for me to get the desired formatting?

    Continue reading...

Compartilhe esta Página