none
NumberFormatInfo.NumberGroupSizes not changing in C# code. RRS feed

  • Question

  • NumberFormatInfo.NumberGroupSizes not changing in C# code.  When I had groupped the digits as 123456,789  then its showing fine in windows setting but when I fetched the NumberGroupSizes in c# code then it shows value as only 3 i.e.

    NumberFormatInfo n =  CultureInfo.CurrentCulture.NumberFormat;

    int[] n1=n.NumberGroupSizes

    then n1 is containing only 3 as value while its length is 1 i.e. n1[0]=3 . Also when I removed the grouping in digits i.e. 123456789 then also it shows the same value.

    Friday, May 15, 2015 7:34 AM

Answers

  • Hello Rajdeep Pathak,

    >> If I do what you say then it would be hard coded which is not required because if I do so and then…

    I do not think the format need to be hard coded, as you can see NumberFormatInfo.NumberGroupSizes is used to specify the format, you could construct an int array at runtime and pass it to this NumberGroupSizes property.

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, May 19, 2015 7:53 AM
    Moderator

All replies

  • Hello Rajdeep Pathak,

    >>then n1 is containing only 3 as value while its length is 1 i.e. n1[0]=3

    If you use your provided code, it is by designed that the value is 3 since the default culture is en-US.

    If you want your C# program to print 123456,789, you could check below code:

    NumberFormatInfo myNfi = new NumberFormatInfo();
    
    
    
                    int[] n1 = { 3, 0 };
    
    
                    myNfi.NumberGroupSizes = n1;
    
    
                    Int64 myInt = 123456789;
    
    
                    // Displays the value with default formatting.
    
                    Console.WriteLine("Default  \t\t:\t{0}", myInt.ToString("N", myNfi));
    

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, May 18, 2015 5:51 AM
    Moderator
  • Actually I had a Grid with a decimal column named Amount in which Amount is to be shown. Now what I want is to get the format in the column as specified in digit grouping  in NumberFormatInfo. If I do what you say then it would be hard coded which is not required because if I do so and then change the digit grouping in windows to 123,456,789 then it would be needed as comma after every 3 digits . What to do for achieving this?
    Monday, May 18, 2015 9:15 AM
  • Hello Rajdeep Pathak,

    >> If I do what you say then it would be hard coded which is not required because if I do so and then…

    I do not think the format need to be hard coded, as you can see NumberFormatInfo.NumberGroupSizes is used to specify the format, you could construct an int array at runtime and pass it to this NumberGroupSizes property.

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, May 19, 2015 7:53 AM
    Moderator