这个问题可能是这个问题的精确复制品: Get number format from OS 但似乎我无法为C#找到合适的解决方案。我不想最终使用操作系统的注册表来使其工作。因为我在C#中,Java的解决方案是不可能的。
请注意
System.Globalization.CultureInfo.CurrentCulture;
System.Globalization.CultureInfo.InstalledUICulture;
System.Globalization.CultureInfo.CurrentUICulture;
它们都没有返回修改后的OS首选项。
例子:en-CA小数是'。'分组将是',#39;。如果我在周围切换它们,则无法通过InstalledUICulture,CurrentUICulture和CurrentCulture恢复修改
答案 0 :(得分:0)
如此MSDN article中所述,CultureInfo.InstalledUICulture属性获取CultureInfo,该文件表示随操作系统一起安装的文化。
此属性具有NumberFormat字段,其中包含您要查找的信息。
答案 1 :(得分:0)
void Main()
{
DescribeIt(System.Globalization.CultureInfo.InstalledUICulture);
DescribeIt(System.Globalization.CultureInfo.CurrentUICulture);
DescribeIt(new System.Globalization.CultureInfo("en-US"));
DescribeIt(new System.Globalization.CultureInfo("fr-FR"));
}
public void DescribeIt(System.Globalization.CultureInfo ci)
{
Console.Write("Culture: {0}", ci);
Console.Write(@"; NumberFormat.NumberGroupSeparator: ""{0}""",
ci.NumberFormat.NumberGroupSeparator);
Console.Write(@"; NumberFormat.NumberDecimalSeparator: ""{0}""",
ci.NumberFormat.NumberDecimalSeparator);
Console.WriteLine();
}
我的机器上的结果:
Culture: en-US NumberFormat.NumberGroupSeparator: "," NumberFormat.NumberDecimalSeparator: "." Culture: en-US NumberFormat.NumberGroupSeparator: "," NumberFormat.NumberDecimalSeparator: "." Culture: en-US NumberFormat.NumberGroupSeparator: "," NumberFormat.NumberDecimalSeparator: "." Culture: fr-FR NumberFormat.NumberGroupSeparator: " " NumberFormat.NumberDecimalSeparator: ","
如果我将Decimal symbol
更改为“。”和Digit grouping
到“,”在“区域和语言控制面板”对话框的“格式”选项卡中的fr-FR设置中,然后运行相同的代码,我得到:
Culture: en-US NumberFormat.NumberGroupSeparator: "," NumberFormat.NumberDecimalSeparator: "." Culture: en-US NumberFormat.NumberGroupSeparator: "," NumberFormat.NumberDecimalSeparator: "." Culture: en-US NumberFormat.NumberGroupSeparator: "," NumberFormat.NumberDecimalSeparator: "." Culture: fr-FR NumberFormat.NumberGroupSeparator: "," NumberFormat.NumberDecimalSeparator: "."
你得到了什么结果?