[code.view]

[top] / python / PyMOTW / decimal / decimal_context_manager.py

     #!/usr/bin/env python
     # encoding: utf-8
     #
     # Copyright (c) 2009 Doug Hellmann All rights reserved.
     #
     """
     """
     #end_pymotw_header
     
     import decimal
     
     with decimal.localcontext() as c:
         c.prec = 2
         print 'Local precision:', c.prec
         print '3.14 / 3 =', (decimal.Decimal('3.14') / 3)
     
     print
     print 'Default precision:', decimal.getcontext().prec
     print '3.14 / 3 =', (decimal.Decimal('3.14') / 3)
     

[top] / python / PyMOTW / decimal / decimal_context_manager.py

contact | logmethods.com