rfmonk

decimal_context_manager.py

Jan 22nd, 2014
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.28 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3.  
  4. import decimal
  5.  
  6. with decimal.localcontext() as c:
  7.     c.prec = 2
  8.     print 'Local precision:', c.prec
  9.     print '3.14 / 3 =', (decimal.Decimal('3.14') / 3)
  10.  
  11. print
  12. print 'Default precision:', decimal.getcontext().prec
  13. print '3.14 / 3 =', (decimal.Decimal('3.14') / 3)
Advertisement
Add Comment
Please, Sign In to add comment