Python | Decimal from_float() method Last Updated : 23 May, 2022 Summarize Comments Improve Suggest changes Share Like Article Like Report Decimal#from_float() : from_float() is a Decimal class method which converts a float to a decimal number, exactly. Syntax: Decimal.from_float() Parameter: Decimal values Return: converts a float to a decimal number, exactly. Code #1 : Example for from_float() method Python3 # Python Program explaining # from_float() method # loading decimal library from decimal import * # Initializing a decimal value a = Decimal(-1) b = Decimal('0.142857') # printing Decimal values print ("Decimal value a : ", a) print ("Decimal value b : ", b) # Using Decimal.from_float() method print ("\n\nDecimal a with from_float() method : ", a.from_float(0.1)) print ("Decimal b with from_float() method : ", b.from_float(float('nan'))) Output : Decimal value a : -1 Decimal value b : 0.142857 Decimal a with from_float() method : 0.1000000000000000055511151231257827021181583404541015625 Decimal b with from_float() method : NaN Code #2 : Example for from_float() method Python3 # Python Program explaining # from_float() method # loading decimal library from decimal import * # Initializing a decimal value a = Decimal('-3.14') b = Decimal('321e + 5') # printing Decimal values print ("Decimal value a : ", a) print ("Decimal value b : ", b) # Using Decimal.from_float() method print ("\n\nDecimal a with from_float() method : ", a.from_float(0.02)) print ("Decimal b with from_float() method : ", b.from_float(float('-inf'))) Output : Decimal value a : -3.14 Decimal value b : 3.21E+7 Decimal a with from_float() method : 0.0200000000000000004163336342344337026588618755340576171875 Decimal b with from_float() method : -Infinity Comment More infoAdvertise with us Next Article Python | Decimal log10() method N noobestars101 Follow Improve Article Tags : Python Practice Tags : python Similar Reads Python | Decimal logb() method Decimal#logb() : logb() is a Decimal class method which returns the adjusted exponent of the Decimal value. Syntax: Decimal.logb() Parameter: Decimal values Return: the adjusted exponent of the Decimal value. Code #1 : Example for logb() method Python3 # Python Program explaining # logb() method # l 2 min read Python | Decimal ln() method Decimal#ln() : ln() is a Decimal class method which returns the natural (base e) logarithm of the Decimal value. Syntax: Decimal.ln() Parameter: Decimal values Return: the natural (base e) logarithm of the Decimal value. Code #1 : Example for ln() method Python3 # Python Program explaining # ln() me 2 min read Python | Decimal log10() method Decimal#log10() : log10() is a Decimal class method which returns the base ten logarithm of the Decimal value. Syntax: Decimal.log10() Parameter: Decimal values Return: the base ten logarithm of the Decimal value. Code #1 : Example for log10() method Python3 # Python Program explaining # log10() met 2 min read Python | Decimal max() method Decimal#max() : max() is a Decimal class method which compares the two Decimal values and return the max of two. Syntax: Decimal.max() Parameter: Decimal values Return: the max of two. Code #1 : Example for max() method Python3 # Python Program explaining # max() method # loading decimal library fro 2 min read Python | Decimal is_finite() method Decimal#is_finite() : is_finite() is a Decimal class method which checks whether the Decimal value is finite value. Syntax: Decimal.is_finite() Parameter: Decimal values Return: true - if the Decimal value is finite value; otherwise false Code #1 : Example for is_finite() method Python3 # Python Pro 2 min read Python | Decimal logical_or() method Decimal#logical_or() : logical_or() is a Decimal class method which returns the digit-wise or of the two Decimal values. Syntax: Decimal.logical_or() Parameter: Decimal values Return: the digit-wise or of the two (logical) of the Decimal values. Code #1 : Example for logical_or() method Python3 # Py 2 min read Like