I'm writing floating point numbers to a text file and I'd really appreciate if Python would stop writing numbers like "0.000002" as "2e-6". What can I do?

有帮助吗?

解决方案

You could use formatting directives, such as this one:

n = 0.000002
print('{:f}'.format(n))
0.000002

more information about formatting see these Python docs

Or old-style if working pre Python v2.6 (thanks @mgilson and @artSwri)

print('%f' % n)

其他提示

>>> "%f" % 2e-6
'0.000002'
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top