2024-09-30 01:21:01 发布
网友
浮动汇率:
fl = 0.000005
将String强制转换为str(fl)=='5e-06'。但是,我希望它转换为str(fl)='0.000005',以便导出到CSV目的
String
str(fl)=='5e-06'
str(fl)='0.000005'
CSV
我如何做到这一点
使用
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'>
您只需使用标准字符串格式选项说明所需的精度
>>> fl = 0.000005 >>> print '%.6f' % fl 0.000005
使用
给予
如果不需要额外的数字,请使用%g(尽管它使用指数表示法,例如0.000005)。例如,见:
给予
您只需使用标准字符串格式选项说明所需的精度
相关问题 更多 >
编程相关推荐