"""$URL: svn+ssh://svn/repos/trunk/dulcinea/lib/cents.py $
$Id: cents.py 25817 2004-12-21 16:27:07Z dbinger $

Provides Cents.
"""
from dulcinea.typeutils import typecheck


class Cents(object):

    """
    Instance attributes:
      cents: int | long
    """
    def __init__(self, value):
        typecheck(value, (int, long))
        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):
        typecheck(other, Cents)
        return Cents(self.cents + other.cents)

    def __sub__(self, other):
        typecheck(other, Cents)
        return Cents(self.cents - other.cents)

    def __cmp__(self, other):
        typecheck(other, Cents)
        return cmp(self.cents, other.cents)

