import decimal

__all__ = ["to_money", "round_to_two_dec", "round_to_four_dec"]


def to_money(something):
    """
    Convert something into a decimal with the correct precision

    >>> to_money('3.76')
    Decimal('3.76')
    >>> to_money('1.87765')
    Decimal('1.88')
    >>> to_money(1.8977987987)
    Decimal('1.90')
    """
    return round_to_two_dec(decimal.Decimal(something))


def round_to_two_dec(number):
    """
    Convert a decimal to 2 digit money notation.

    >>> a = decimal.Decimal('3.7555999')
    >>> a
    Decimal('3.7555999')
    >>> round_to_two_dec(a)
    Decimal('3.76')
    >>> round_to_two_dec(a) == decimal.Decimal('3.76')
    True
    """
    return number.quantize(decimal.Decimal("0.01"), decimal.ROUND_HALF_UP)


def round_to_four_dec(number):
    """
    Convert a decimal to 4 digit money notation.

    >>> a = decimal.Decimal('3.7555999')
    >>> a
    Decimal('3.7555999')
    >>> round_to_four_dec(a)
    Decimal('3.7556')
    >>> round_to_four_dec(a) == decimal.Decimal('3.7556')
    True
    """
    return number.quantize(decimal.Decimal("0.0001"), decimal.ROUND_HALF_UP)
