def roundup(ctx, number, num_digits): """ Rounds a number up, away from zero """ number = conversions.to_decimal(number, ctx) num_digits = conversions.to_integer(num_digits, ctx) return decimal_round(number, num_digits, ROUND_UP)
def rounddown(ctx, number, num_digits): """ Rounds a number down, toward zero """ number = conversions.to_decimal(number, ctx) num_digits = conversions.to_integer(num_digits, ctx) return decimal_round(number, num_digits, ROUND_DOWN)
def _round(ctx, number, num_digits): """ Rounds a number to a specified number of digits """ number = conversions.to_decimal(number, ctx) num_digits = conversions.to_integer(num_digits, ctx) return decimal_round(number, num_digits, ROUND_HALF_UP)