C#: When would the NumberDecimalSeparator be different to the CurrencyDecimalSeparator

Refresh

February 2019

Views

1.1k time

1

My application allows the user to capture a numeric value. In the context I do not know whether they are capturing a currency value or some other numeric amount. I need to cater for different decimal separators and grouping separators, but which should I choose from the CultureInfo?

Does anyone know in what circumstances the NumberDecimalSeparator and CurrencyDecimalSeparator are likely to be different?

1 answers

4

This is pretty easy to check for predefined cultures:

using System;
using System.Globalization;

class Test
{
    static void Main()
    {
        foreach (var culture in CultureInfo.GetCultures(CultureTypes.AllCultures))
        {
            var formatInfo = culture.NumberFormat;
            if (formatInfo.NumberDecimalSeparator != 
                formatInfo.CurrencyDecimalSeparator)
            {
                Console.WriteLine("{0}: {1} {2}",
                                  culture,
                                  formatInfo.NumberDecimalSeparator,
                                  formatInfo.CurrencyDecimalSeparator);
            }
        }
    }
}

Results on my box:

et: , .
tg: , ;
fa: . /
kk: , -
ky: , -
tzm: , .
ps: , ?
prs: , .
et-EE: , .
tg-Cyrl-TJ: , ;
fa-IR: . /
kk-KZ: , -
ky-KG: , -
ps-AF: , ?
prs-AF: , .
tzm-Latn-DZ: , .
en-ZA: . ,
tg-Cyrl: , ;
tzm-Latn: , .