diff --git a/python/FracAndDec.py b/python/FracAndDec.py index 88530e4..2eb0e76 100644 --- a/python/FracAndDec.py +++ b/python/FracAndDec.py @@ -1,10 +1,11 @@ import decimal -import fractions +from fractions import Fraction as Frac class Dec(decimal.Decimal): - def __Fraction__(self): - return self.__new__(self.numerator) / self.__new__(self.denominator) + def __new__(cls,value="0",context=None): + if isinstance(value, Frac): + return super().__new__(cls,value.numerator,context) / super().__new__(cls,value.denominator,context) + else: + return super().__new__(cls,value,context) getcontext = decimal.getcontext - -Frac = fractions.Fraction