return Amount(self.currency, abs(self.value))
def __add__(self, other):
+ if other == 0:
+ return self
if other.currency != self.currency and other.value * self.value != 0:
raise Exception("Summing amounts must be done with same currencies")
return Amount(self.currency, self.value + other.value)
raise Exception("Summing amounts must be done with same currencies")
return Amount(self.currency, self.value - other.value)
+ def __rsub__(self, other):
+ if other == 0:
+ return -self
+ else:
+ return -self.__sub__(other)
+
def __mul__(self, value):
if not isinstance(value, (int, float, D)):
raise TypeError("Amount may only be multiplied by numbers")