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
# 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)) |
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
# 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)) |
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
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.