import decimal


def round(val, digits, mode = decimal.ROUND_HALF_UP):
    """
    Round a decimal value to the given number of decimal places,
    using the given rounding mode, or the standard ROUND_HALF_UP
    if not specified
    """
    return val.quantize(decimal.Decimal("10") ** -digits, mode)