Bug 40697

Summary: Some NumberFormat have wrong GroupSeparator
Product: [Mono] Class Libraries Reporter: Robert van der Boon <rjvdboon>
Component: mscorlibAssignee: Marek Safar <masafa>
Severity: normal CC: masafa, mono-bugs+mono
Priority: ---    
Version: master   
Target Milestone: Untriaged   
Hardware: PC   
OS: Linux   
Tags: Is this bug a regression?: ---
Last known good build:

Description Robert van der Boon 2016-04-26 11:44:59 UTC
In some culture we get a roundtrip error when we ToString/Parse using the {0:N} format.
This is probably due to the fact that on Mono for these cultures the same string is defined as both NumberDecimalSeparator as NumberGroupSeparator.

In the Mono csharp REPL the following script:
using System.Globalization;
foreach(var culture in CultureInfo.GetCultures(CultureTypes.SpecificCultures))
  if (culture.NumberFormat.NumberDecimalSeparator == culture.NumberFormat.NumberGroupSeparator)
    Console.WriteLine("Culture error: {0} (decimalSep:'{1}', groupSep:'{2}')", culture.Name, culture.NumberFormat.NumberDecimalSeparator, culture.NumberFormat.NumberGroupSeparator);

Culture error: tg-Cyrl-TJ (decimalSep:',', groupSep:',')
Culture error: hy-AM (decimalSep:'.', groupSep:'.')
Culture error: km-KH (decimalSep:'.', groupSep:'.')
Culture error: lo-LA (decimalSep:'.', groupSep:'.')
Culture error: sah-RU (decimalSep:',', groupSep:',')
Culture error: ar-LY (decimalSep:'.', groupSep:'.')
Culture error: ar-TN (decimalSep:'.', groupSep:'.')
Culture error: ar-LB (decimalSep:'.', groupSep:'.')

Whereas on plain .Net this outputs nothing.

The result is that the following code works for both cultures on .Net framework, while it fails on mono for (in this example) tg_Cryl_TJ:
double v = 123456.789;
var ciNL = System.Globalization.CultureInfo.CreateSpecificCulture("nl-NL");
var ciTJ = System.Globalization.CultureInfo.CreateSpecificCulture("tg-Cyrl-TJ");
double.Parse(v.ToString("N", ciNL), ciNL); // Succeeds on .Net and Mono
double.Parse(v.ToString("N", ciTJ), ciTJ); // Succeeds on .Net, throws FormatException on Mono

NOTE: On the .Net framework (windows 7 x64) the definition for the failing cultures is:
tg-Cyrl-TJ (decimalSep:',', groupSep:' ')
hy-AM (decimalSep:'.', groupSep:',')
km-KH (decimalSep:'.', groupSep:',')
lo-LA (decimalSep:'.', groupSep:',')
sah-RU (decimalSep:',', groupSep:' ')
ar-LY (decimalSep:'.', groupSep:',')
ar-TN (decimalSep:'.', groupSep:',')
ar-LB (decimalSep:'.', groupSep:',')
i.e. the group separator on mono is different from .Net framework
Comment 1 Marek Safar 2016-05-04 13:28:52 UTC
Fixed in master