Python | Decimal same_quantum() method
Last Updated :
09 Sep, 2019
Decimal#same_quantum() : same_quantum() is a Decimal class method which checks whether the two operands have the same exponent.
Syntax: Decimal.same_quantum()
Parameter: Decimal values
Return: true – if the two operands have the same exponent; otherwise false
Code #1 : Example for same_quantum() method
from decimal import *
a = Decimal( - 1 )
b = Decimal( '0.142857' )
print ( "Decimal value a : " , a)
print ( "Decimal value b : " , b)
print ( "\n\nDecimal a with same_quantum() method : " , a.same_quantum(b))
print ( "Decimal b with same_quantum() method : " , b.same_quantum(b))
|
Output :
Decimal value a : -1
Decimal value b : 0.142857
Decimal a with same_quantum() method : False
Decimal b with same_quantum() method : True
Code #2 : Example for same_quantum() method
from decimal import *
a = Decimal( '-3.14' )
b = Decimal( '321e + 5' )
print ( "Decimal value a : " , a)
print ( "Decimal value b : " , b)
print ( "\n\nDecimal a with same_quantum() method : " , a.same_quantum(b))
print ( "Decimal b with same_quantum() method : " , b.same_quantum(b))
|
Output :
Decimal value a : -3.14
Decimal value b : 3.21E+7
Decimal a with same_quantum() method : False
Decimal b with same_quantum() method : True
Share your thoughts in the comments
Please Login to comment...