Windows货币符号

时间:2012-08-16 14:20:59

标签: c# .net windows-7 localization

我想获取Windows使用的货币符号;可以使用控制面板中的区域和语言选项查看和修改此符号。

RegionInfo.CurrentRegion表示当前线程中使用的语言的区域信息;因此,RegionInfo.CurrentRegion.CurrencySymbol不一定与操作系统用户选择的货币符号匹配。

如果我只修改区域和语言中的货币符号> 高级设置...... > 货币,我希望能够从C#程序访问该符号。怎么办呢?

感谢您阅读我的帖子。

5 个答案:

答案 0 :(得分:3)

RegionInfo未反映用户更改的设置。我觉得像

CultureInfo.CurrentCulture.NumberFormat.CurrencySymbol

会奏效。

ADDITION (接受回答后):

我测试了一下,似乎在某些情况下RegionInfo 确实反映了用户设置。即使the spec说:与CultureInfo相比,RegionInfo不代表用户的偏好,也不依赖于用户的语言或文化。

在我的Windows 7 PC上,我得到了这样的结果:RegionInfo确实反映了用户设置,即使我构建new RegionInfo实例(而不是使用{{} 1}} getter)。所以现在我们很困惑。

答案 1 :(得分:2)

可以在RegionInfo.CurrencySymbol

中找到

答案 2 :(得分:1)

你确定你原来的假设是对的吗?当我在“地区和语言>其他设置>货币>货币符号”下更改/编辑货币符号时

以下更改根据:

RegionInfo.CurrentRegion.CurrencySymbol

答案 3 :(得分:0)

这是我今天学到的一些问题 - 我的代码验证了我的发现如下。我将我的系统设置为西班牙语 - 多米尼加共和国,并更改了货币符号来自" RD $"到" $"。然后我将我的文化/ UI文化设置为es-DO而不是en-US。

  • 使用number.ToString("C2")不遵循用户自定义设置。因此,如果您将System.Globalization.CultureInfo.CurrentCulture / CurrentUICulture设置为es-DO并执行1.00M.ToString("C2"),则会返回RD $ 1.00。

  • 要让它实际使用用户自定义设置,您必须拥有var info = new CultureInfo("es-DO")变量,然后根据上述更改使用string.Format(info, "{0:C2}", 1.00M)获得预期的$ 1.00。

  • 您无法使用string.Format(CultureInfo.CurrentCulture, "{0:C2}", 1.00M),因为它不会返回用户自定义项 - 在这种情况下,它会返回RD $ 1.00。

我认为这很愚蠢,但如果有人知道这种行为背后的真正原因,请分享,因为我很好奇。

这里是repro的代码:

var esdo = new CultureInfo("en-US");
{en-US}
esdo = new CultureInfo("es-DO");
{es-DO}
var resdo = new RegionInfo("es-DO");
{es-DO}
        CurrencyEnglishName: "Dominican Peso"
        CurrencyNativeName: "Peso"
        CurrencySymbol: "$"
        DisplayName: "Dominican Republic"
        EnglishName: "Dominican Republic"
        GeoId: 65
        IsMetric: true
        ISOCurrencySymbol: "DOP"
        Name: "es-DO"
        NativeName: "República Dominicana"
        ThreeLetterISORegionName: "DOM"
        ThreeLetterWindowsRegionName: "DOM"
        TwoLetterISORegionName: "DO"
esdo.NumberFormat
{System.Globalization.NumberFormatInfo}
        CurrencyDecimalDigits: 2
        CurrencyDecimalSeparator: "."
        CurrencyGroupSeparator: ","
        CurrencyGroupSizes: {int[1]}
        CurrencyNegativePattern: 1
        CurrencyPositivePattern: 0
        CurrencySymbol: "$"
        DigitSubstitution: None
        IsReadOnly: false
        NaNSymbol: "NeuN"
        NativeDigits: {string[10]}
        NegativeInfinitySymbol: "-Infinito"
        NegativeSign: "-"
        NumberDecimalDigits: 2
        NumberDecimalSeparator: "."
        NumberGroupSeparator: ","
        NumberGroupSizes: {int[1]}
        NumberNegativePattern: 1
        PercentDecimalDigits: 2
        PercentDecimalSeparator: "."
        PercentGroupSeparator: ","
        PercentGroupSizes: {int[1]}
        PercentNegativePattern: 1
        PercentPositivePattern: 1
        PercentSymbol: "%"
        PerMilleSymbol: "‰"
        PositiveInfinitySymbol: "Infinito"
        PositiveSign: "+"
var dsa = 1.00M;
string.Format(esdo,"{0:C2}",dsa)
"$1.00"
dsa.ToString("C2")
"RD$1.00"
string.Format(System.Globalization.CultureInfo.CurrentCulture,"{0:C2}",dsa)
"RD$1.00"
string.Format(System.Globalization.CultureInfo.CurrentUICulture,"{0:C2}",dsa)
"RD$1.00"
System.Globalization.CultureInfo.CurrentUICulture
{es-DO}
string.Format(esdo,"{0:C2}",dsa)
"$1.00"

答案 4 :(得分:-1)

//    Do something like that maybe
public static string getSeparator()
        {
            string output = string.Empty;
            try
            {
                RegistryKey reg = Registry.CurrentUser.OpenSubKey("Control Panel").OpenSubKey("International");
                output = reg.GetValue(EnumClass.String.sList.ToString(), output).ToString();

                reg.Dispose();
            }`enter code here`
            catch (Exception ie)
            {
                // catch error
            }
            return output;
        }
相关问题