diff --git a/pydicts/percentage.py b/pydicts/percentage.py index 7924e34..92b289c 100644 --- a/pydicts/percentage.py +++ b/pydicts/percentage.py @@ -1,72 +1,62 @@ -from logging import warning from decimal import Decimal ## Class to manage percentages in spreadsheets +## Converts values to decimal (Value is a decimal) class Percentage: def __init__(self, numerator=None, denominator=None): - self.setValue(self.toDecimal(numerator),self.toDecimal(denominator)) - - def toDecimal(self, o): - if o==None: - return o - if o.__class__.__name__ in ["Currency", "Money"]: - return o.amount - elif o.__class__.__name__=="Decimal": - return o - elif o.__class__.__name__ in ["int", "float"]: - return Decimal(o) - elif o.__class__.__name__=="Percentage": - return o.value - else: - warning (o.__class__.__name__) - return None + + self.setValue(numerator, denominator) def __repr__(self): return self.string() def __neg__(self): - if self.value==None: - return self + if self.value is None: + return Percentage(None) return Percentage(-self.value, 1) def __lt__(self, other): - if self.value==None: - value1=Decimal('-Infinity') - else: - value1=self.value - if other.value==None: - value2=Decimal('-Infinity') - else: - value2=other.value - if value1