1

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!

Ted T
  • 13
  • 4

1 Answers1

1

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
mozway
  • 194,879
  • 13
  • 39
  • 75
  • That's perfect thanks! Is there a good site to understand g,e,d and so one more in contexts like this? – Ted T Oct 14 '21 at 14:31
  • You can read [PEP 3101](https://www.python.org/dev/peps/pep-3101/), especially the [Standard Format Specifiers](https://www.python.org/dev/peps/pep-3101/#standard-format-specifiers) section. To be honest I have no clue why `g` and `e` behave differently in your case, it should be the same for numbers that require an exponent… – mozway Oct 14 '21 at 14:34