Integer.FromString locale bug?

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

Tried?:

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”

Sorry, that was typo when I switched from locale.current to a manually created one.
Same exception.

Forgot to say I am on Mac.

On windows 10 both Desktop and Console 32-bit and 64-bit works:

output is:

123.456.789

debugger shows the same.

Probably a Xojo on MacOS bug …?

p.s. both “de_DE” and “de-DE” should be valid (not sure how xojo handles it).

Here’s how Xojo handles it :slight_smile:
https://documentation.xojo.com/api/os/locale.html#locale-constructor(localeidentifier_as_string)

Edit: Further reading suggests de_DE would be wrong:

Yes, obviously. Thanks for confirming it is ok on Windows. Did not test there yet.

1 Like

Definately… tested on macOS big sur x64 and “de-DE” doesn’t do what it’s suppose to do.

try “nl-NL” it’s suppose to be the same, and it seems to work on my “nl-NL” machine.

For “de-DE” this happens:

Thanks for your help!
<https://xojo.com/issue/63596>

2 Likes

@DerkJ: I think we had the same idea at the same time :smiley:

1 Like

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 :slight_smile: .

2 Likes

I am not into soccer/football/whatever you call it, but make that rather 1:1: :smiley:

3 Likes

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 :wink:

3 Likes

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.

Did you try the sample code from: https://documentation.xojo.com/api/data_types/integer.html#integer-fromstring ?

Var locale As New Locale("en-US")
Var value As Integer
value = Integer.FromString("1,234", locale) // value = 1234

I get the same RuntimeException (1,234 is not a valid integer).

1 Like

Change the 0 to #

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.

1 Like

Marking it now as solution made my laugh hard (exactly my sense of humor) but I’m afraid this will now be closed case :slight_smile:

1 Like

:smiley:
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 …)

of course, no worries, I just found it “funny”: Problem solved, because it is fundamentally broken elsewhere :-).

That’s what I did as well. Works, but it is a shame, as theoretically we are close to a very elegant solution, if it would work.

1 Like