Python | Decimal remainder_near() method
Last Updated :
09 Sep, 2019
Decimal#remainder_near() : remainder_near() is a Decimal class method which returns x – y * n, where n is the integer nearest the exact value of x / y
Syntax: Decimal.remainder_near()
Parameter: Decimal values
Return: x – y * n, where n is the integer nearest the exact value of x / y
Code #1 : Example for remainder_near()
method
from decimal import *
a = Decimal( - 1 )
b = Decimal( '0.142857' )
print ( "Decimal value a : " , a)
print ( "Decimal value b : " , b)
print ( "\n\nDecimal a with remainder_near() method : " , a.remainder_near(b))
print ( "Decimal b with remainder_near() method : " , b.remainder_near(b))
|
Output :
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
Code #2 : Example for remainder_near()
method
from decimal import *
a = Decimal( '-3.14' )
b = Decimal( '321e + 5' )
print ( "Decimal value a : " , a)
print ( "Decimal value b : " , b)
print ( "\n\nDecimal a with remainder_near() method : " , a.remainder_near(b))
print ( "Decimal b with remainder_near() method : " , b.remainder_near(b))
|
Output :
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
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...