unified-font-object/ufoNormalizer

xmlConvertFloat() converts 0.99999999999 to "0"

justvanrossum opened this issue · 1 comments

Found in LucasFonts/vfbLib#94

def xmlConvertFloat(value):
    if FLOAT_FORMAT is None:
        string = repr(value)
        if "e" in string:
            string = "%.16f" % value
    else:
        string = FLOAT_FORMAT % value
    if "." in string:
        string = string.rstrip("0")
        if string[-1] == ".":
            return xmlConvertInt(int(value))
    return string

The string formatting has rounded the value to 1.0000000000, then the trailing zeros are stripped, then the last char is "." and then the int is taken from the original value, which is still 0.99999999999, so the result is "0".

This PR seems to cover that already: #90