def scale_to_percent(val, min, max):
    """
    Utility function to scale a given value to a percentage within a range
    """
    current = val
    
    # first, ensure that current is within our defined min/max
    if val < min:
        current = min
    elif current > max:
        current = max

    # now, we scale it to b/t 0 and 1
    scaled = (current-min)/(max - min)

    return scaled * 100