from typing import Union


def round_number(n: float) -> Union[int, float]:
    """Round a number based on its size."""
    abs_n = abs(n)
    if abs_n >= 10000:
        return round(n)
    elif abs_n >= 100:
        return round(n, 1)
    elif abs_n >= 1:
        return round(n, 2)
    else:
        return round(n, 3)