简体   繁体   English

如何减少 python 中 output 中指数数尾数部分的小数位

[英]how to decrease the decimal places in the mantissa part of an exponential number in an output in python

THE CODE编码

avogadro = 6.0225e23 # define Avogadro number
at_wt = 63.55
print ("atomic weight of copper = 63.55")
print("weight of an atom = atomic weight/Avogadro's number")
x = at_wt/ avogadro
print ("Weight of one atom of copper = {}".format(x) )

THE OUTPUT
atomic weight of copper = 63.55
weight of an atom = atomic weight/Avogadro's number
Weight of one atom of copper = 1.0552096305520962e-22

I am interested that in the output 1.0552096305520962e-22, I would like that the mantissa part of the exponential number displays only 3 decimal points instead of so many.我感兴趣的是在 output 1.0552096305520962e-22 中,我希望指数数的尾数部分只显示 3 个小数点而不是这么多。 Hence, what command should I use to achieve the desired result.因此,我应该使用什么命令来达到预期的结果。

Use a better format string:使用更好的格式字符串:

print ("Weight of one atom of copper = {:0.3e}".format(x) )

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

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