Python‎ > ‎

decimal


Introduction
Python reference guide defines the decimal has floating point which are enchained in discretionary limits.

Examples
The return is:
 >>> .25+.25+.214/.25
1.3559999999999999
>>> from decimal import Decimal
>>> Decimal('.4')+Decimal('.3')-Decimal('.24')
Decimal('0.46')
>>> 

if statement (string is decimal)
if statement test whether string object is decimal or not
 x="122cc"
if x.isdecimal():
print("yes, you're right")
else:
print("It is not Decimal")

>>> 
it is not Decimal
>>>

The method test the equality tow Decimal equations.
from decimal import Decimal

x=(Decimal(1).logical_and(Decimal(1))).__sub__(Decimal(0).logical_and(Decimal(1)))
y=(Decimal(1).logical_and(Decimal(1))).__mul__(Decimal(0).logical_and(Decimal(1)))
print(x.__eq__(y))

>>> 
False
>>>




Subpages (44): View All
Comments