Setting Precision in Python Using Decimal Module
The decimal module in Python can be used to set the precise value of a number. The default value of the Decimal module is up to 28 significant figures. However, it can be changed using getcontext().prec method.
The below program demonstrates the use of decimal module by computing the square root of 2 numbers up to the default the number of places.
We can set the precision up to n significant figure. The decimal.getcontext().prec has to be declared in the global scope such that all the decimal objects can have n significant figures.
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course