Advertisement
rfmonk

decimal_instance_context.py

Jan 22nd, 2014
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.33 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3.  
  4. import decimal
  5.  
  6. # Set up a context with limited precision
  7. c = decimal.getcontext().copy()
  8. c.prec = 3
  9.  
  10. # Create our constant
  11. pi = c.create_decimal('3.1415')
  12.  
  13. # The constant value is rounded off
  14. print 'PI   :', pi
  15.  
  16. # The result of using the constant uses the global context
  17. print 'RESULT:', decimal.Decimal('2.01') * pi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement