Runtime exception on Windows and not on Mac

Hello

I am developing on Mac with the last xojo release.
When I run on Window 10 my application I got a:
“Invalidargumentexception bad format”
runtime error on this line:

Var CalcArea_item_area As String = Areacmq_item.ToString(Locale.Current,“###.###,##”)

This line is running on Mac without any errors, but crash on Windows.
Any idea, I am the first sw who will run also on windows.

Thank you very much

According to the format that Xojo uses for ToString:
https://unicode.org/reports/tr35/tr35-4.html#Number_Format_Patterns
your format pattern should be "###,###.##" and the locale should change the ‘,’ and ‘.’ to what the locale should use.

I’m not sure if that is the problem with your error and don’t know why it works on Mac and not on Windows.

Are the locales on your Mac and Windows machines the same? If not, do they both allow the . As a thousands separator and a , as a decimal separator?

1 Like

Alberto pointed the correct universal format string where “.” is always at the decimal separator position while the results vary obeying the locale rules.

Probably due to some bug it is silently failing on the Mac and generating a wrong “formatted” value, and avoiding it while pointing the error on Windows. Is Areacmq_item a Double?

I have exactly the same apps on Mac and Windows. On Windows, I had to work extra to remove exceptions. Apparently, the platform is less tolerant than Mac.

I would say a bug. Different ICU libs and/or exception handling? Xojo, not OS.

Perhaps Xojo. I was simply reporting my experience.

A very welcomed one, I was just reporting a possible bug and inconsistency needing attention. :wink:

This information is in another topic.

In the means time I have found the solution:
On Mac was working in this way: “###.###,##” (European way to write double numbers)
But the formatted string need to be write in US way: “###,###.##”

Is not clear way on Mac do not raise an exception like on windows

Thank you to all
Sergio

It does not make sense, it should cause wrong and invalid values.

Read the docs: Double — Xojo documentation

https://unicode.org/reports/tr35/tr35-4.html#Number_Format_Patterns

Tested this code and it runs without a problem on my mac:

Var Areacmq_item As Double = 1234.56
Var CalcArea_item_area As String = Areacmq_item.ToString(Locale.Current,"###.###,##")

image

And that’s is a wrong behavior. The mask does not follow the locale, the mask follows the Number Format Patterns, the result string follows the provided locale.

That’s a bug, not a feature. Windows is correct, Mac is wrong. Please open an Issue Report

@Sergio_Molino can you open a ticket for this? I don’t have a Windows machine to do screenshots (if needed).

Windows is correctly detecting a bad format

Once fixed, it works as stated in the ICU / Xojo docs

Mac and Linux should follow the standard.

1 Like

Case #70530

1 Like

Thank you Alberto to rise an issue.
The exception error on Windows was exactly that: “Bad format”

Confirmed on Mac, so thumbs up on the bug from me.