簡體   English   中英

如何減少 python 中 output 中指數數尾數部分的小數位

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

編碼

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

我感興趣的是在 output 1.0552096305520962e-22 中,我希望指數數的尾數部分只顯示 3 個小數點而不是這么多。 因此,我應該使用什么命令來達到預期的結果。

使用更好的格式字符串:

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