[Tutor] python precision output?

Kent Johnson kent37 at tds.net
Thu Dec 6 23:55:30 CET 2007


Andre Walker-Loud wrote:
> To reiterate, I need str(value) to be written to my file with 16  
> digits of precision...???

You can use string formatting to specify exactly how many decimal places 
to include:

In [1]: v=1.0/7
In [2]: v
Out[2]: 0.14285714285714285
In [3]: str(v)
Out[3]: '0.142857142857'
In [4]: '%.16f' % v
Out[4]: '0.1428571428571428'

Kent


More information about the Tutor mailing list