I think I found another API 2 locale bug – but maybe it was already reported or I err.
Can someone please confirm this?
By the docs, Integer.FromString should be able to read a formatted integer value.
The following (here in a console run event) will throw a runtime exception:
123.456.789 is not a valid integer.
(which it is in German)
Function Run(args() as String) Handles Run as Integer
Var loc As New Locale ("de-DE")
Var i As Integer = 123456789
Var s As String = i.ToString(loc, "###,###,###,###")
Print s
i = Integer.FromString(s, loc)
End Function
Function Run(args() as String) Handles Run as Integer
Var loc As New Locale ("de_DE")
Var i As Integer = 123456789
Var s As String = i.ToString(loc, "###,###,###,###")
Print s
i = Integer.FromString(s, loc)
End Function
On Desktop (windows 10) 32-bit works perfect both “de_DE” and “de-DE”
Confirms my experience with the locales. Never had time to dive into it and preferred working around it. I found a similar issue while working on Xojo Web 2. As well with de-DE. Didn’t have the idea to try another European locale. Good, I learned 2 things. NL beats Germany 1:0, and I now know how a screenshot is called in Dutch: Schermafbeelding .
P.S.: I wish someone would invent a unit test so Xojo could have automated quality assurance and get rid of these nasty bugs before they manifest in a release. Something like https://github.com/xojo/XojoUnit
Tried with NL locale, but that causes an exception on my Mac as well. You put a leading 0 at the beginning of the format string which changes the format to, well, unformatted.
Yes sure. Then it will fire an exception.
As Alberto found out, I was wrong. It is not the locale. Integer.FromString is not working at all; it will cause an exception even with the US demo code.
It is the final solution to my question if there’s something wrong with Integer.FromString. Not a solution for those running into the bug of course.
I worked around it by removing all locale.GroupSeparators in the suspected Integer before parsing it …
(And I hope that the ticket will still stay valid)
(Edited typo. It wasn’t the final solution to my answer …)