Setting Precision in Python Using Decimal Module Last Updated : 01 Oct, 2020 Summarize Comments Improve Suggest changes Share Like Article Like Report 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. Python3 # Import required modules import decimal # Create decimal object ob1 = decimal.Decimal(5).sqrt() ob2 = decimal.Decimal(7).sqrt() # Display value print(ob1) print(ob2) Output2.236067977499789696409173669 2.645751311064590590501615754 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. Python3 # Import required module import decimal # Set precision to a fixed value decimal.getcontext().prec = 6 # Create Decimal object ob1 = decimal.Decimal(5).sqrt() ob2 = decimal.Decimal(7).sqrt() # Display value up to 6 significant figures print(ob1) print(ob2) Output2.23607 2.64575 Comment More infoAdvertise with us Next Article Python | Decimal to_eng_string() method S sangy987 Follow Improve Article Tags : Misc Python python-utility Practice Tags : Miscpython Similar Reads PyQt5 QDoubleSpinBox â Setting Decimal Precision In this article we will see how we can set decimal precision of the QDoubleSpinBox. By default decimal precision of double spin box is 2 although we can change it any time. Decimal precision is the number of digits to the right of the decimal point in a number. For example, the number 123.45 has a d 2 min read Python | Decimal to_eng_string() method Decimal#to_eng_string() : to_eng_string() is a Decimal class method which converts to a string, using engineering notation if an exponent is needed. Syntax: Decimal.to_eng_string() Parameter: Decimal values Return: converts to a string Code #1 : Example for to_eng_string() method Python3 # Python Pr 2 min read Decimal Functions in Python | Set 1 Python in its definition provides certain methods to perform faster decimal floating point arithmetic using the module "decimal". Important operations on Decimals1. sqrt() :- This function computes the square root of the decimal number.2. exp() :- This function returns the e^x (exponent) of the deci 5 min read PyQt5 QDoubleSpinBox â Getting Decimal Precision In this article we will see how we can get the decimal precision of the QDoubleSpinBox. By default decimal precision of double spin box is 2 although we can change it any time with the help of setDecimals method. Decimal precision is the number of digits to the right of the decimal point in a number 2 min read Python | Decimal is_subnormal() method Decimal#is_subnormal() : is_subnormal() is a Decimal class method which checks whether the Decimal value is subnormal. Syntax: Decimal.is_subnormal() Parameter: Decimal values Return: true - if the Decimal value is subnormal otherwise false Code #1 : Example for is_subnormal() method Python3 # Pytho 2 min read Precision Handling in Python Python in its definition allows handling the precision of floating-point numbers in several ways using different functions. Most of them are defined under the "math" module. In this article, we will use high-precision calculations in Python with Decimal in Python.ExampleInput: x = 2.4Output: Integra 6 min read Like