def validate_and_clean_float(param, value, valmin=None, valmax=None):
    """
            Validates that a clinical parameter are within an allowed value range
        :param param: Clinical parameter
        :param value: value of the parameter
        :param valmin: lowest allowed value of this parameter
        :param valmax: highest allowed value of this parameter
        :return: validated parameter
        """
    try:
        value_vc = float(value)

        if valmax is not None:
            if value_vc > valmax:
                raise Exception(
                    'Value {} of clinical parameter "{}" exceeds allowed bounds of [{}:{}]'.format(value_vc, param,
                                                                                                   valmin, valmax))

        if valmin is not None:
            if value_vc < valmin:
                raise Exception(
                    'Value {} of clinical parameter "{}" exceeds allowed bounds of [{}:{}]'.format(value_vc, param,
                                                                                                   valmin, valmax))

    except ValueError:
        raise Exception(
            'Value {} of clinical parameter "{}" could not be parsed to float. Aborting.'.format(value, param))

    return value_vc