📜  Python|小数 radix() 方法

📅  最后修改于: 2022-05-13 01:55:08.864000             🧑  作者: Mango

Python|小数 radix() 方法

Decimal#radix() : radix()是一个 Decimal 类方法,它返回基数值 10,因为这是 Decimal。

代码 #1:radix() 方法的示例

# Python Program explaining 
# radix() 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.radix() method
print ("\n\nDecimal a with radix() method : ", a.radix())
  
print ("Decimal b with radix() method : ", b.radix())

输出 :

Decimal value a :  -1
Decimal value b :  0.142857


Decimal a with radix() method :  10
Decimal b with radix() method :  10

代码 #2:radix() 方法的示例

# Python Program explaining 
# radix() method
  
# loading decimal library
from decimal import *
  
  
# Initializing a decimal value
a = Decimal('-3.14545454')
  
b = Decimal('321e + 5')
  
  
# printing Decimal values
print ("Decimal value a : ", a)
print ("Decimal value b : ", b)
  
  
# Using Decimal.radix() method
print ("\n\nDecimal a with radix() method : ", a.radix())
  
print ("Decimal b with radix() method : ", b.radix())

输出 :

Decimal value a :  -3.14545454
Decimal value b :  3.21E+7


Decimal a with radix() method :  10
Decimal b with radix() method :  10