Saturday, November 16, 2024
Google search engine
HomeLanguagesPython | Decimal same_quantum() method

Python | Decimal same_quantum() method

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




# Python Program explaining 
# same_quantum() 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.same_quantum() method
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




# Python Program explaining 
# same_quantum() 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.same_quantum() method
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

Dominic Rubhabha-Wardslaus
Dominic Rubhabha-Wardslaushttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Recent Comments