NumberFormatInfo.NumberGroupSizes 속성

정의

숫자 값에서 정수 부분의 각 그룹 자릿수를 가져오거나 설정합니다.

public:
 property cli::array <int> ^ NumberGroupSizes { cli::array <int> ^ get(); void set(cli::array <int> ^ value); };
public int[] NumberGroupSizes { get; set; }
member this.NumberGroupSizes : int[] with get, set
Public Property NumberGroupSizes As Integer()

속성 값

Int32[]

숫자 값에서 정수 부분의 각 그룹 자릿수입니다. InvariantInfo의 기본값은 3으로 설정된 하나의 요소만 있는 1차원 배열입니다.

예외

속성이 null로 설정되어 있습니다.

속성이 설정되거나 배열에 0보다 작거나 9보다 큰 항목이 포함되어 있습니다.

또는

속성이 설정되거나 배열의 마지막 항목 이외의 항목이 0으로 설정되어 있습니다.

속성이 설정되어 있으며 NumberFormatInfo 개체가 읽기 전용입니다.

예제

다음 예제에서는 변경의 효과 보여 줍니다.는 NumberGroupSizes 속성입니다.

using namespace System;
using namespace System::Globalization;
int main()
{
   
   // Gets a NumberFormatInfo associated with the en-US culture.
   CultureInfo^ MyCI = gcnew CultureInfo( "en-US",false );
   NumberFormatInfo^ nfi = MyCI->NumberFormat;
   
   // Displays a value with the default separator (S".").
   Int64 myInt = 123456789012345;
   Console::WriteLine( myInt.ToString( "N", nfi ) );
   
   // Displays the same value with different groupings.
   array<Int32>^mySizes1 = {2,3,4};
   array<Int32>^mySizes2 = {2,3,0};
   nfi->NumberGroupSizes = mySizes1;
   Console::WriteLine( myInt.ToString( "N", nfi ) );
   nfi->NumberGroupSizes = mySizes2;
   Console::WriteLine( myInt.ToString( "N", nfi ) );
}

/*
This code produces the following output.
123, 456, 789, 012, 345.00
12, 3456, 7890, 123, 45.00
1234567890, 123, 45.00
*/
using System;
using System.Globalization;

class NumberFormatInfoSample {

   public static void Main() {

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

      // Displays a value with the default separator (".").
      Int64 myInt = 123456789012345;
      Console.WriteLine( myInt.ToString( "N", nfi ) );

      // Displays the same value with different groupings.
      int[] mySizes1 = {2,3,4};
      int[] mySizes2 = {2,3,0};
      nfi.NumberGroupSizes = mySizes1;
      Console.WriteLine( myInt.ToString( "N", nfi ) );
      nfi.NumberGroupSizes = mySizes2;
      Console.WriteLine( myInt.ToString( "N", nfi ) );
   }
}


/*
This code produces the following output.

123,456,789,012,345.00
12,3456,7890,123,45.00
1234567890,123,45.00
*/
Imports System.Globalization

Class NumberFormatInfoSample

   Public Shared Sub Main()

      ' Gets a NumberFormatInfo associated with the en-US culture.
      Dim nfi As NumberFormatInfo = New CultureInfo("en-US", False).NumberFormat

      ' Displays a value with the default separator (".").
      Dim myInt As Int64 = 123456789012345
      Console.WriteLine(myInt.ToString("N", nfi))

      ' Displays the same value with different groupings.
      Dim mySizes1 As Integer() =  {2, 3, 4}
      Dim mySizes2 As Integer() =  {2, 3, 0}
      nfi.NumberGroupSizes = mySizes1
      Console.WriteLine(myInt.ToString("N", nfi))
      nfi.NumberGroupSizes = mySizes2
      Console.WriteLine(myInt.ToString("N", nfi))

   End Sub

End Class


'This code produces the following output.
'
'123,456,789,012,345.00
'12,3456,7890,123,45.00
'1234567890,123,45.00

다음 예제에서는 서로 다른 값을 출력 NumberGroupSizes 배열입니다.

using namespace System;
using namespace System::Globalization;
String^ PrintArraySet( array<Int32>^myArr )
{
   String^ myStr = nullptr;
   myStr = myArr[ 0 ].ToString();
   for ( int i = 1; i < myArr->Length; i++ )
      myStr = String::Concat( myStr, ", ", myArr[ i ].ToString() );
   return myStr;
}

int main()
{
   
   // Creates a new NumberFormatinfo.
   NumberFormatInfo^ myNfi = gcnew NumberFormatInfo;
   
   // Takes a long value.
   Int64 myInt = 123456789012345;
   
   // Displays the value with default formatting.
   Console::WriteLine( "Default  \t\t:\t{0}", myInt.ToString( "N", myNfi ) );
   
   // Displays the value with three elements in the GroupSize array.
   array<Int32>^newInts1 = {2,3,4};
   myNfi->NumberGroupSizes = newInts1;
   Console::WriteLine( "Grouping ( {0} )\t:\t{1}", PrintArraySet( myNfi->NumberGroupSizes ), myInt.ToString( "N", myNfi ) );
   
   // Displays the value with zero as the last element in the GroupSize array.
   array<Int32>^newInts2 = {2,4,0};
   myNfi->NumberGroupSizes = newInts2;
   Console::WriteLine( "Grouping ( {0} )\t:\t{1}", PrintArraySet( myNfi->NumberGroupSizes ), myInt.ToString( "N", myNfi ) );
}

/*
This code produces the following output. 

Default               :       123, 456, 789, 012, 345.00
Grouping (2, 3, 4)    :       12, 3456, 7890, 123, 45.00
Grouping (2, 4, 0)    :       123456789, 0123, 45.00
*/
using System;
using System.Globalization;
class SamplesNumberFormatInfo  {

   public static void Main()  {

      // Creates a new NumberFormatinfo.
      NumberFormatInfo myNfi = new NumberFormatInfo();

      // Takes a long value.
      Int64 myInt = 123456789012345;

      // Displays the value with default formatting.
      Console.WriteLine( "Default  \t\t:\t{0}", myInt.ToString( "N", myNfi ) );

      // Displays the value with three elements in the GroupSize array.
      myNfi.NumberGroupSizes = new int[]  { 2, 3, 4 };
      Console.WriteLine( "Grouping ( {0} )\t:\t{1}",
         PrintArraySet( myNfi.NumberGroupSizes ), myInt.ToString( "N", myNfi ) );

      // Displays the value with zero as the last element in the GroupSize array.
      myNfi.NumberGroupSizes = new int[]  { 2, 4, 0 };
      Console.WriteLine( "Grouping ( {0} )\t:\t{1}",
         PrintArraySet( myNfi.NumberGroupSizes ), myInt.ToString( "N", myNfi ) );
   }

   public static string PrintArraySet( int[] myArr )  {
      string myStr = null;
      myStr = myArr[0].ToString();
      for ( int i = 1; i < myArr.Length; i++ )
         myStr += ", " + myArr[i].ToString();
      return( myStr );
   }
}
/*
This code produces the following output.

Default                 :       123,456,789,012,345.00
Grouping ( 2, 3, 4 )    :       12,3456,7890,123,45.00
Grouping ( 2, 4, 0 )    :       123456789,0123,45.00
*/
Imports System.Globalization

Class SamplesNumberFormatInfo
    
    Public Shared Sub Main()
        
        ' Creates a new NumberFormatinfo.
        Dim myNfi As New NumberFormatInfo()
        
        ' Takes a long value.
        Dim myInt As Int64 = 123456789012345
        
        ' Displays the value with default formatting.
        Console.WriteLine("Default  " + ControlChars.Tab + ControlChars.Tab _
           + ":" + ControlChars.Tab + "{0}", myInt.ToString("N", myNfi))
        
        ' Displays the value with three elements in the GroupSize array.
        myNfi.NumberGroupSizes = New Integer() {2, 3, 4}
        Console.WriteLine("Grouping ( {0} )" + ControlChars.Tab + ":" _
           + ControlChars.Tab + "{1}", _
           PrintArraySet(myNfi.NumberGroupSizes), myInt.ToString("N", myNfi))
        
        ' Displays the value with zero as the last element in the GroupSize array.
        myNfi.NumberGroupSizes = New Integer() {2, 4, 0}
        Console.WriteLine("Grouping ( {0} )" + ControlChars.Tab + ":" _
           + ControlChars.Tab + "{1}", _
           PrintArraySet(myNfi.NumberGroupSizes), myInt.ToString("N", myNfi))
    End Sub
    
    
    Public Shared Function PrintArraySet(myArr() As Integer) As String
        Dim myStr As String = Nothing
        myStr = myArr(0).ToString()
        Dim i As Integer
        For i = 1 To myArr.Length - 1
            myStr += ", " + myArr(i).ToString()
        Next i
        Return myStr
    End Function
End Class

' This code produces the following output. 
' 
' Default                 :       123,456,789,012,345.00
' Grouping ( 2, 3, 4 )    :       12,3456,7890,123,45.00
' Grouping ( 2, 4, 0 )    :       123456789,0123,45.00

설명

값을 NumberGroupSizes 속성 "N"을 사용 하 여 서식이 지정 된 숫자 값의 결과 영향을 줍니다. 사용자 지정 숫자 형식 문자열 또는 기타 표준 숫자 서식 문자열을 사용 하는 값의 경우는 NumberGroupSizes 속성은 무시 됩니다.

1 차원 배열의 모든 요소에는 1에서 9 사이의 정수 여야 합니다. 마지막 요소에는 0 일 수 있습니다.

자릿수의 왼쪽에 바로 가장 중요 하지 않은 그룹의 요소 수를 정의 하는 배열의 첫 번째 요소는 NumberDecimalSeparator합니다. 각 후속 요소에서 이전 그룹의 왼쪽으로 자릿수 다음 중요 한 그룹을 가리킵니다. 배열의 마지막 요소 다음 위치에 있는 경우 0이 아닌 나머지 숫자는 기준으로 그룹화 배열의 마지막 요소입니다. 마지막 요소의 0 인 경우에 나머지 자릿수 그룹화 되지 않습니다.

예를 들어, 배열 {3, 4, 5}를 포함 하는 경우 숫자 "55,55555,55555,55555,4444,333.00" 비슷합니다 그룹화 됩니다. 배열 {3, 4, 0}에 숫자 "55555555555555555,4444,333.00" 비슷합니다 그룹화 됩니다.

적용 대상

추가 정보