[英]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.