fr-CH locale and decimal point not correctly parsed's Avatar

18 Mar, 2020 04:10 PM

We have a problem with the "fr-CH" locale and some decimal separator. Some of our unit tests fail because in AppVeyor, the decimal separator for "fr-CH" is "." (dot) instead of "," (comma).

Here is a simplified version of a unit test (nUnit format) that fails:

[TestCase("fr-CH", "12,35")]
public void DummyTest_To_Check_Locale_AppVeyor(string locale, string expectedFormattedNumber)
  string formattedNumber = string.Format(new CultureInfo(locale), "{0}", 12.35);

  Assert.AreEqual(expectedFormattedNumber, formattedNumber, string.Format("Check failed for locale {0}", locale));

Locally, the test passes: the number 12.35 is formatted to "12,35". But on AppVeyor, it is formatted to "12.35".

Here is also a fiddle to show correct formatting:

  1. Support Staff 1 Posted by Feodor Fitsner on 18 Mar, 2020 05:25 PM

    Feodor Fitsner's Avatar

    Is it .NET Core or .NET Framework project/tests?

  2. 2 Posted by on 18 Mar, 2020 06:01 PM's Avatar

    We use .Net Framework 4.5.2.

  3. Support Staff 3 Posted by Feodor Fitsner on 18 Mar, 2020 07:41 PM

    Feodor Fitsner's Avatar

    Here is the test:

    I see correct behavior on Visual Studio 2019 image while 2015 and 2017 are wrong. That's interesting to notice that the latest version of .NET 4.8 is installed on all images.

    My guess it's related to the operating system as localization routines are OS-dependent (i.e. have native implementation). You are running your local tests on Windows 10, right? Visual Studio 2019 image is based on Windows Server 2019 which has the same core as Windows 10.

    I bet if we run the same code as .NET Core we'll get correct and consistent result on all images.

    Use Visual Studio 2019 image then?

  4. Support Staff 4 Posted by Feodor Fitsner on 18 Mar, 2020 07:50 PM

    Feodor Fitsner's Avatar

    Apparently, .NET Core behaves the same:, so looks like in both .NET Framework and Core it's OS-dependent :-/

    Image OSes:

  5. 5 Posted by on 19 Mar, 2020 07:33 AM's Avatar

    Using Visual Studio 2019 works, thanks for the quick answer!

    A sidenote: on no SDK is listed for the 2019 image, but our code compiles correctly anyway.

  6. closed this discussion on 19 Mar, 2020 07:33 AM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts


? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac