def conv_to_number(val, conv):
    """Convert a string to a number

    Can apply either a k (thousand) or M (million) multiplier

    Parameter
    ---------
    val : str
      String representing the number
    conv
      Function to apply to final number, float/int

    Example
    -------
    ('100k', int) -> 100,000
    ('5.6M', float) -> 5,600,000.0

    """
    if val[-1].isalpha():
        val, suffix = val[:-1], val[-1]
        try:
            multi = {'k': 1000.0, 'M': 1000000.0}[suffix]
        except KeyError:
            raise ValueError('Unrecognised suffix {}'.format(suffix))
    else:
        multi = 1
    return conv(float(val) * multi)
