def perc_range(n, min_val, max_val, rounding=2):
    """
    Return percentage of `n` within `min_val` to `max_val` range. The
    ``rounding`` argument is used to specify the number of decimal places to
    include after the floating point.

    Example::

        >>> perc_range(40, 20, 60)
        50

    """
    return round(
        min([1, max([0, n - min_val]) / (max_val - min_val)]) * 100, rounding)