简体   繁体   English

如何使用 .3g 保留尾随零点?

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

I have the following value: 6.095651174e-09 and I am printing it like this:我有以下值:6.095651174e-09,我正在打印它:

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 .这里的输出是6.1e-09但我想在它从6.09舍入到6.1后保留零。 My desired output would be: 6.10我想要的输出是: 6.10

A normal float works with this.一个正常的浮动适用于此。 But with g it does not work anymore.但是使用 g 它不再起作用了。 I want to keep the E at the end and therefore I want to stay with g (and not f).我想将 E 保留在最后,因此我想保留 g(而不是 f)。

Is it possible to have 6.10e-09 printed out here?是否可以在此处打印6.10e-09 I only found things for float and those solutions did not work with my case.我只找到了浮动的东西,而这些解决方案对我的案例不起作用。

Thanks for every help!感谢您的每一个帮助!

I don't have the issue with the e type:我没有e类型的问题:

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

Output:输出:

result:  6.10e-09 N

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM