Quick actions

cmd+k|ctrl+k

Navigation

Languages

decimal

Snippet info

Language

Python

Visibility

public

Author

dnf668

Created

2025-05-13T06:13:37.431265Z

Updated

2025-05-13T06:13:37.431265Z

import decimal
from decimal import Decimal  # Correctly importing Decimal from decimal module

# Creating a Decimal object using the tuple form: (sign, digits, exponent)
print(Decimal((0, (3, 1, 4, 1, 5), -4)))  # Prints 0.31415

a= Decimal('0.12345')
b= Decimal('0.12345')
print(a+b)
with decimal.localcontext() as ctx:
    ctx.prec = 2
    c= a + b
    print('c within local context: {0}'.format(c))
print('c whthin global context: {0}'.format(c))
c = c+b

print(c)
print(globals())
INFO