How to do it...

Because the official documentation (https://docs.python.org/3/library/decimal.html) comprises more than 35 pages, this section will only provide a brief examination of the decimal module:

  1. When using the decimal module, it is a good idea to figure out what the current conditions are and modify them, if needed:

In this case, getcontext tells us the following:

    • The system is set for 28 places of precision.
    • Rounding is to the nearest whole value with ties going to the nearest even integer.
    • Emin and Emax are the bottom/top limits allowed for exponents.
    • Capital letters are used for designating exponents, for example, 1.2E+12 ...

Get Secret Recipes of the Python Ninja now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.