Python‎ > ‎decimal‎ > ‎

Decimal.next_toward()


Introduction
If the two operands are unequal, return the number closest to the first operand in the direction of the second operand.

Syntax
Decimal(x).next_toward(y)

Parameters
x=Decimal
y=numeric

Examples
The value is:
 >>> Decimal(1).next_toward(1)
Decimal('1')
>>> Decimal(1).next_toward(0)
Decimal('0.9999999999999999999999999999')
>>> Decimal(1).next_toward(2)
Decimal('1.000000000000000000000000001')
>>>

The return is:
 from decimal import Decimal
import operator

a=Decimal(1).radix()
b=Decimal(1.3).next_toward(2)
y=operator.lt(a,b)
print("The value a lesser than b: ", y)
>>>
The value a lesser than b: False
>>>


Comments