Python float to string, only “dotted notation”?
-
11-06-2021 - |
题
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'
不隶属于 StackOverflow