With these changes LocalizedNumberExtractor supports decimal numbers with no leading zeros, e.g. ",2" for locale de_AT will be 0.2.
The one thing that's tricky is to bypass the check if the string is a valid number string. LocalizedNumberExtractor.canParseString only returns true, if the NumberFormatter can parse the string – "," cannot be parsed.
What I do instead is to check if the string is a valid prefix string, which means it only contains the decimal separator. I also have to check for start == 0 because of cases where , is used as the argument separator in functions. Because of this workaround I'm unable to parse "-,2" as -0.2.
With these changes
LocalizedNumberExtractor
supports decimal numbers with no leading zeros, e.g.",2"
for localede_AT
will be0.2
.The one thing that's tricky is to bypass the check if the string is a valid number string.
LocalizedNumberExtractor.canParseString
only returns true, if theNumberFormatter
can parse the string –","
cannot be parsed.What I do instead is to check if the string is a valid prefix string, which means it only contains the decimal separator. I also have to check for
start == 0
because of cases where,
is used as the argument separator in functions. Because of this workaround I'm unable to parse"-,2"
as-0.2
.@davedelong Do you know a better way to do this?