def get_float_formatter_func(precision=None, thousands_sep=False,
                             zero_string='0'):
    """
    Returns a function that gives ``zero_string`` if the float is 0, else
    a string with the given digits of precision.

    """

    def float_formatter(f):
        if isinstance(f, str):
            return f

        if thousands_sep:
            ts = ','
        else:
            ts = ''
        if precision is not None:
            prec = '.' + str(precision) + 'f'
        elif float(f).is_integer():
            prec = '.0f'
        else:
            prec = ''

        fmt = '{:' + ts + prec + '}'

        try:
            if f == 0:
                return zero_string
            elif (precision is not None) or (thousands_sep is not None):
                return fmt.format(f)
            else:
                return str(f)
        except ValueError:
            return f
    return float_formatter