more decimal places needed in python

Use repr(), print uses str() which reduces the number of decimal digits to 12 to make the output user friendly.

In [17]: a=0.123456789101997

In [18]: str(a)
Out[18]: '0.123456789102'

In [19]: repr(a)
Out[19]: '0.123456789101997'

or string formatting:

In [21]: "{0:.15f}".format(a)
Out[21]: '0.123456789101997'

How about trying the Decimal module?

In [2]: import decimal

In [3]: d = decimal.Decimal('0.123456789101997')

In [4]: print d
0.123456789101997

Tags:

Python