当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


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。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。