question

ThomasOD-7935 avatar image
0 Votes"
ThomasOD-7935 asked Viorel-1 edited

issue with the thousands separator character in French

Hello,

we are software publishers, some of which in WPF.
our code encounters a problem with the transition to Windows 11.
The following line:

   int.TryParse("1 036", System.Globalization.NumberStyles.AllowThousands, System.Globalization.CultureInfo.CreateSpecificCulture("fr-FR"), out int points)

correct under Windows 10 and earlier returns 1036, for the points variable.
On the other hand under Windows 11, it returns "false".

After several searches, it turns out that the thousand separator character present by default for the French language has changed?!

This is really problematic, because we can't ask all of our Windows 11 users to change their regional settings.

Do you have a solution to propose or a corrective update of this point planned?

Thanks in advance.
Best regards,

Thomas




dotnet-csharpwindows-wpf
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Viorel-1 avatar image
0 Votes"
Viorel-1 answered

Try this workaround:

 var nf = System.Globalization.CultureInfo.CreateSpecificCulture( "fr-FR" ).NumberFormat;
 nf.NumberGroupSeparator = " ";
    
 int.TryParse( "1 036", System.Globalization.NumberStyles.AllowThousands, nf, out int points );

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

ThomasOD-7935 avatar image
0 Votes"
ThomasOD-7935 answered Viorel-1 edited

@Viorel-1 Thanks for your workaround which will definitely work, however, it will cause me to change dozens of lines of code in our apps, maybe even hundreds... (we do a lot of math) and I'd rather the solution come from source ;)
But thanks again for your useful contribution!

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.


If you have hundreds of such CreateSpecificCulture lines, you can replace them with a custom function using Find and Replace feature. What real lines do you have to change?

You can also build and set an adjusted culture for your application on startup.


0 Votes 0 ·