programming-examples/python/Math/Get the local and default precision.py

9 lines
303 B
Python
Raw Normal View History

2019-11-15 12:59:38 +01:00
import decimal
with decimal.localcontext() as context:
context.prec = 2
print('Local precision:', context.prec)
print('22/7 =', (decimal.Decimal('22') / 7))
print()
print('Default precision:', decimal.getcontext().prec)
print('22 /7 =', (decimal.Decimal('22') / 7))