[英]Casting float to string without scientific notation
浮動:
fl = 0.000005
轉換為String
作為str(fl)=='5e-06'
。 但是,我希望它轉換為str(fl)='0.000005'
以導出到CSV
目的。
我如何實現這一目標?
您可以只使用標准字符串格式選項說明您想要的精度
>>> fl = 0.000005
>>> print '%.6f' % fl
0.000005
用
fl = 0.00005
s = '%8.5f' % fl
print s, type(s)
給
0.00005 <type 'str'>
如果您不需要額外的數字,請使用 %g(盡管它使用指數表示法,例如 0.000005)。 見例如:
fl = 0.0005
s = '%g' % fl
print s, type(s)
fl = 0.005
s = '%g' % fl
print s, type(s)
給
0.0005 <type 'str'>
0.005 <type 'str'>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.