import math


def present_value_csv(key, val, values_with_ci):
    """ Turns a value into a state where it can be presented in a CSV file,
        including its confidence interval if the column it appears in has
        confidence intervals somewhere in it.
    """
    if key in values_with_ci:
        ciDown, ciUp = val.ci()
        if math.isnan(ciDown):
            return '%f,%f,%f' % (val.value(), val.value(), val.value())
        else:
            return '%f,%f,%f' % (val.value(), ciDown, ciUp)
    else:
        return str(val)