“ en-IN”的NumberGroupSizes Windows Server 2012中的文化错误 [英] NumberGroupSizes for "en-IN" culture in windows server 2012 is wrong

查看:64
本文介绍了“ en-IN”的NumberGroupSizes Windows Server 2012中的文化错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

en-IN区域性的NumberGroupSizes设置为3,2,0,这是错误的,理想情况下,在Windows Server 2012中将其设置为3,2。

NumberGroupSizes for "en-IN" culture is set as 3,2,0 which is wrong and ideally be set as 3,2 in windows server 2012.

// Gets a NumberFormatInfo associated with the en-IN culture.
NumberFormatInfo nfi = new CultureInfo("en-IN", false).NumberFormat;

// Displays a value with the default separator (".").
Int64 myInt = 123456789012345;

Console.WriteLine(myInt.ToString("N", nfi));

上面在Windows Server 2012上运行的代码显示为1234567890,12,345.00,这是错误的。理想情况下应为12,34,56,78,90,12,345.00

The above code ran on windows server 2012 gives out put as 1234567890,12,345.00 which is wrong. Ideally it should be 12,34,56,78,90,12,345.00

推荐答案

其背后的原因是存储在 NumberFormatInfo.NumberGroupSizes 属性。对于文化 zh-cn,此属性的值为 {3,2,0} ,这意味着左数小数的第一组将有3位数字,下一组将会有2位数字,其余的数字不会被分组。

The reason behind this is the values stored in NumberFormatInfo.NumberGroupSizes property. For culture "en-IN" this property has values {3,2,0} which means first group of the number left to the decimal point will have 3 digits, next group will be have 2 digits and rest of the number will not be grouped.

您可以通过运行此代码进行检查。

You can check by as running this code.

public static void Main()
{
    NumberFormatInfo nfi = new CultureInfo("en-IN", false).NumberFormat;

    Int64 myInt = 123456789012345;

    Console.WriteLine("NumberGroupSizes.Length : {0}", nfi.NumberGroupSizes.Length);
    for(var i = 0;i<nfi.NumberGroupSizes.Length; i++)
    {
        Console.WriteLine("NumberGroupSizes[{0}] : {1}", i, nfi.NumberGroupSizes[i]);
    }
    Console.WriteLine(myInt.ToString("N",nfi));

如果您使用 en-US文化创建NumberFormatInfo,则 NumberGroupSizes中将只有一个值属性,该值是 3,因此输出将数字分成3位数字。

If you create NumberFormatInfo using "en-US" culture it will have only one value in "NumberGroupSizes" property and that value is "3" so the output will divide the number in groups of 3 digits.

NumberFormatInfo nfi = new CultureInfo("en-US", false).NumberFormat;

Int64 myInt = 123456789012345;

Console.WriteLine(myInt.ToString("N", nfi));
// The output will 123,456,789,012,345.00

要解决您的问题,您需要将新值设置为

To solve your issue you need to set new values to the NumberGroupSizes property of the NumberFormatInfo as following.

public static void Main()
{
    NumberFormatInfo nfi = new CultureInfo("en-IN", false).NumberFormat;

    Int64 myInt = 123456789012345;

    int[] x = {3,2};
    nfi.NumberGroupSizes = x;
    Console.WriteLine(myInt.ToString("N",nfi));
    //The output will be 12,34,56,78,90,12,345.00
}

我希望这能解决您的问题。

I hope this will resolve your issue.

这篇关于“ en-IN”的NumberGroupSizes Windows Server 2012中的文化错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆