Decimal.to_integral()


Definition
Identical to the to_integral_value() method. 

Syntax
Decimal(x).to_integral()

Parameters
x=Decimal

Examples
The output is:
 >>> Decimal(0).to_integral()
Decimal('0')
>>> Decimal(-1).to_integral()
Decimal('-1')
>>> Decimal(1.1).to_integral()
Decimal('1')
>>> Decimal(1.9).to_integral()
Decimal('2')
>>> Decimal(1.5000001).to_integral()
Decimal('2')
>>> 

The method return with the difference in the set items:

The returns are following:
from decimal import Decimal
import itertools

set1={Decimal(0.1).to_integral_value(),Decimal(1.9).to_integral_exact(),
                        Decimal(1.5000001).to_integral()Decimal(10).shift(2)}
set2={Decimal(1).scaleb(0),Decimal(1).remainder_near(2),Decimal(1.0000).normalize()}

print("The decimal values of set1 are:", set1)
print("The decimal values of set2 are: ", set2)

max_set1=int(max({Decimal(0.1).to_integral_value(),Decimal(1.9).to_integral_exact(),
Decimal(1.5000001).to_integral(), Decimal(10).shift(2)}))
print("The maximum integer value in set1 is: ",max_set1)

min_set2=int(min({Decimal(1).scaleb(0),Decimal(1).remainder_near(2),Decimal(1.0000).normalize()}))
print("The minimum integer value in set2 is:",min_set2)

set3=max_set1.__add__(min_set2)
print("The set1 added by set2 is: ", set3) 

set4=max_set1.__lt__(min_set2)
print("The max_set1 is lessor than min_set2:", set4)

x=set1.difference(set2)
rint("The set1 difference to set2 is :", x)

>>> 
The decimal values of set1 are: {Decimal('1000'), Decimal('0'), Decimal('2')}
The decimal values of set2 are: {Decimal('1')}
The maximum integer value in set1 is: 1000
The minimum integer value in set2 is: 1
The set1 added by set2 is: 1001
The max_set1 is lessor than min_set2: False
The set1 difference to set2 is : {Decimal('1000'), Decimal('0'), Decimal('2')}
>>>



Comments