""" open/dulcinea/lib/cents.py """ from qp.lib.spec import require, specify, Specified class Cents (Specified): cents_is = int def __init__(self, value=0): specify(self, cents=value) def get_cents(self): return self.cents def __str__(self): return "$%.02f" % self.get_dollars() def get_dollars(self): return self.cents / 100.0 def __add__(self, other): require(other, Cents) return Cents(self.cents + other.cents) def __sub__(self, other): require(other, Cents) return Cents(self.cents - other.cents) def __eq__(self, other): require(other, Cents) return self.cents == other.cents def __ne__(self, other): require(other, Cents) return self.cents != other.cents def __gt__(self, other): require(other, Cents) return self.cents > other.cents def __ge__(self, other): require(other, Cents) return self.cents >= other.cents def __lt__(self, other): require(other, Cents) return self.cents < other.cents def __le__(self, other): require(other, Cents) return self.cents <= other.cents