def float_to_string(f):
    """Unitiliy float encoding which clamps floats close to 0 and 1 and uses %g instead of repr()."""
    if abs(f) < 1e-06:
        return '0'
    elif abs(1 - f) < 1e-06:
        return '1'
    return '%g' % f
