python中remainder_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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值