Question

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?

Était-ce utile?

La solution

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)

Autres conseils

>>> "%f" % 2e-6
'0.000002'
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top