issue with the thousands separator character in French

Thomas OD 1 Reputation point
2022-05-17T13:05:38.67+00:00

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

Windows Presentation Foundation
Windows Presentation Foundation
A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
2,795 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
11,111 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Viorel 118.5K Reputation points
    2022-05-17T14:13:51.653+00:00

    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 );
    
    0 comments No comments

  2. Thomas OD 1 Reputation point
    2022-05-17T15:03:09.497+00:00

    @Viorel 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!


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.