當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


Python Decimal remainder_near()用法及代碼示例


Decimal#remainder_near():remainder_near()是一個Decimal類方法,它返回x – y * n,其中n是最接近x /y確切值的整數。

用法: Decimal.remainder_near()

參數:十進製值


返回:x – y * n,其中n是最接近x /y確切值的整數

代碼1:的示例remainder_near()方法

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

輸出:

Decimal value a :  -1
Decimal value b :  0.142857


Decimal a with remainder_near() method :  -0.000001
Decimal b with remainder_near() method :  0.000000

代碼2:示例remainder_near()方法

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

輸出:

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


Decimal a with remainder_near() method :  -3.14
Decimal b with remainder_near() method :  0E+5



相關用法


注:本文由純淨天空篩選整理自noobestars101大神的英文原創作品 Python | Decimal remainder_near() method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。