-1

I use decimal objects whose values get close to zero. By default, a statement such as

print (decimal.Decimal('0.00000000004') / decimal.Decimal('2'))

will output 2E-11. How do I prevent this from happening and get 0.00000000002 instead?

Moronic
  • 141
  • 2
  • 9
  • possible duplicate of [How do I suppress scientific notation in Python?](http://stackoverflow.com/questions/658763/how-do-i-suppress-scientific-notation-in-python) – suhailvs Jul 08 '14 at 09:08
  • 1
    `'{0:f}'.format(decimal.Decimal('0.00000000004') / decimal.Decimal('2'))` – suhailvs Jul 08 '14 at 09:09

2 Answers2

1

To get the decimal point You need to format the print

print "{:.11f}".format(decimal.Decimal('0.00000000004') / decimal.Decimal('2'))
sundar nataraj
  • 8,524
  • 2
  • 34
  • 46
0
num = decimal.Decimal('0.00000000004') / decimal.Decimal('2')
print '{:.50f}'.format(num)
print '{:.2f}'.format(num)

You can read more in documentation

spinus
  • 5,497
  • 2
  • 20
  • 26