Decimal.from_float()


Definition
The method that converts a float to a decimal number, exactly.

Syntax
Decimal.from_float(x)

Parameters
x=float()

Examples
The return are:
 >>> Decimal.from_float(.1)
Decimal('0.100000000000000005551115
1231257827021181583404541015625')
>>>
>>> Decimal.from_float(.211)
Decimal('0.210999999999999993
1166172473240294493734836578369140625')
>>>
>>> Decimal().from_float(.3311)

Decimal('0.3311000000000000054178
88360170763917267322540283203125')
>>>

The returns are following:
 >>> a=Decimal.from_float(.1)
>>> b=Decimal('0.100000000000000005551115
1231257827021181583404541015625')
>>> b=Decimal('0.1000000000000000055511151231257827021181583404541015625')
>>> operator.eq(a,b)
True
>>> operator.sub(a,b)
Decimal('0E-55')
>>> operator.gt(a,b)
False
>>> operator.add(a,b)
Decimal('0.2000000000000000111022302463')
>>>


Comments