Search code examples
pythonnumbersdecimalsignificant-digits

How can I keep the trailing zereos with .3g?


I have the following value: 6.095651174e-09 and I am printing it like this:

print(f' the result is: {forces[index]: .3g} N') 

Here the output is 6.1e-09 but I want to keep the zero after it was rounded from 6.09 to 6.1. My desired output would be: 6.10

A normal float works with this. But with g it does not work anymore. I want to keep the E at the end and therefore I want to stay with g (and not f).

Is it possible to have 6.10e-09 printed out here? I only found things for float and those solutions did not work with my case.

Thanks for every help!


Solution

  • I don't have the issue with the e type:

    i = 6.0956e-9
    print(f'result: {i: .2e} N')
    

    Output:

    result:  6.10e-09 N