Python‎ > ‎Fraction‎ > ‎

Fraction.from_decimal()

http://www.adilwaseem.com/

Definition
The method return Fraction from the decimal.

Syntax
Fraction(x).from_decimal(y)

Parameters
x=number
y=decimal

Examples
The return is:
 >>> 
>>> Fraction(2.1).from_decimal(1)
Fraction(1, 1)
>>> Fraction(1).from_decimal(1)
Fraction(1, 1)
>>> Fraction(0).from_decimal(1)
Fraction(1, 1)
>>> Fraction(1).from_decimal(0)
Fraction(0, 1)

__eq__
The method tested the equality:
 >>> Fraction(1).from_decimal(0).__eq__(Fraction(0,1))
True

__ge__
The method tested whether the equation is greater or equal to other.
 >>> Fraction(1).from_decimal(1).__ge__(Fraction(0,1))
True

__add__
The method added the values.
 >>> Fraction(1).from_decimal(1).__add__(Fraction(0,1))
Fraction(1, 1)

__sub__
The method subtracted the values.
 >>> Fraction(1).from_decimal(1).__sub__(Fraction(0,1))
Fraction(1, 1)

__ne__
The method tested whether the values are not equal.
 >>> Fraction(1).from_decimal(1).__ne__(Fraction(0,1))
True
>>>
Comments