Explore the `decimal` module

We are exposed to the decimal module in one of the Python units (needs attribution). Mind, we’re ankle deep and must needs get into deeper water to really understand this module. This writer is among the ankle deep waders, hence this appeal to other learners to contribute their questions, and advanced learners, their insights on this topic.

Consider,

>>> import decimal
>>> from math import pi as PI
>>> context = decimal.getcontext().copy()
>>> context.prec = 7
>>> pi = context.create_decimal(PI)
>>> pi
Decimal('3.141593')
>>> PI
3.141592653589793
>>> float(pi)
3.141593
>>> 

Is there another way to produce a physical value dialed into the precision of the above? Not that I know of. We evidently have a very powerful tool for working with SIGDIGS. The floor is open to discussion…

decimal – Fixed and floating point math

1 Like