def round_base(num, base=1):
    """
    Returns a number *num* (*int* or *float*) rounded to an arbitrary *base*. Example:

    .. code-block:: python

       round_base(7, 3)   # => 6
       round_base(18, 5)  # => 20
       round_base(18., 5) # => 20. (float)
    """
    return num.__class__(base * round(float(num) / base))