import re


def _scale_val(val, scale_factor):
    """
    Parse out the number from a kubernetes resource string and scale it by scale_factor

    Numbers are rounded to 1 decimal place.

    Examples:
    * "500Mi" scaled by .1 returns "50.0Mi"
    * "2" scaled by .5 returns "1"
    * "200m" scaled by 2 returns "400m"
    """
    match = re.match(r"(\d+)(\.\d+)?([A-Za-z]+)?", val)
    if match:
        base_num, decimal, unit = match.groups()
    else:
        return val
    float_num = float("{}{}".format(base_num, decimal if decimal else ".0"))
    return "{}{}".format(str(round(float_num * scale_factor, 1)), unit if unit else "")