def convert_variable(datatype, variable):
    """
    Convert variable to number (float/int)
    Used for dataset metadata and for query string
    :param datatype: type to convert to
    :param variable: value of variable
    :return: converted variable
    :raises: ValueError
    """
    try:
        if variable and datatype == "int":
            variable = int(variable)
        elif variable and datatype == "float":
            variable = float(variable)
        return variable
    except ValueError:
        raise