다음을 통해 공유


NumberFormatInfo.NumberGroupSizes 속성

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

네임스페이스: System.Globalization
어셈블리: mscorlib(mscorlib.dll)

구문

‘선언
Public Property NumberGroupSizes As Integer()
‘사용 방법
Dim instance As NumberFormatInfo
Dim value As Integer()

value = instance.NumberGroupSizes

instance.NumberGroupSizes = value
public int[] NumberGroupSizes { get; set; }
public:
property array<int>^ NumberGroupSizes {
    array<int>^ get ();
    void set (array<int>^ value);
}
/** @property */
public int[] get_NumberGroupSizes ()

/** @property */
public void set_NumberGroupSizes (int[] value)
public function get NumberGroupSizes () : int[]

public function set NumberGroupSizes (value : int[])

속성 값

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

예외

예외 형식 조건

ArgumentNullException

속성이 Null 참조(Visual Basic의 경우 Nothing)로 설정되는 경우

ArgumentException

속성을 설정하고 배열에 0보다 작거나 9보다 큰 항목이 들어 있는 경우

- 또는 -

속성을 설정하고 배열에 마지막 항목이 아닌 0으로 설정된 항목이 있는 경우

InvalidOperationException

속성이 설정되어 있으며 NumberFormatInfo는 읽기 전용인 경우

설명

1차원 배열의 모든 요소는 1부터 9까지의 정수여야 합니다. 마지막 요소는 0일 수 있습니다.

배열의 첫째 요소가 NumberDecimalSeparator로 구분되는 최하위 그룹 자릿수를 정의합니다. 다음에 나오는 각 요소는 이전 그룹의 왼쪽에 있는 다음 유효 그룹 자릿수를 나타냅니다. 배열의 마지막 요소가 0이 아닌 경우 나머지 자릿수는 배열의 마지막 요소에 따라 그룹화됩니다. 마지막 요소가 0인 경우 나머지 자릿수는 그룹화되지 않습니다.

예를 들어, 배열에 { 3, 4, 5 }가 들어 있는 경우 자릿수는 "55,55555,55555,55555,4444,333.00"처럼 그룹화됩니다. 배열에 { 3, 4, 0 }이 들어 있으면 자릿수는 "55555555555555555,4444,333.00"처럼 그룹화됩니다.

예제

다음 코드 예제에서는 NumberGroupSizes 속성의 변경 내용이 적용된 결과를 보여 줍니다.

Imports System
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 'Main 

End Class 'NumberFormatInfoSample



'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
*/
   
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
*/
import System.*;
import System.Globalization.*;

class NumberFormatInfoSample
{
    public static void main(String[] args)
    {
        // Gets a NumberFormatInfo associated with the en-US culture.
        NumberFormatInfo nfi = 
            (new CultureInfo("en-US", false)).get_NumberFormat();
        // Displays a value with the default separator (".").
        Int64 myInt = (Int64)(123456789012345L);
        Console.WriteLine(myInt.ToString("N", nfi));
        // Displays the same value with different groupings.
        int mySizes1[] =  { 2, 3, 4 };
        int mySizes2[] =  { 2, 3, 0 };
        nfi.set_NumberGroupSizes(mySizes1);
        Console.WriteLine(myInt.ToString("N", nfi));
        nfi.set_NumberGroupSizes(mySizes2);
        Console.WriteLine(myInt.ToString("N", nfi));
    } //main 
} //NumberFormatInfoSample

/* 
This code produces the following output.

123,456,789,012,345.00
12,3456,7890,123,45.00
1234567890,123,45.00
*/

다음 코드 예제에서는 다양한 NumberGroupSizes 배열을 사용하여 값을 출력합니다.

Imports System
Imports System.Globalization
Imports Microsoft.VisualBasic

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 
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
*/
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
*/
import System
import System.Globalization
import System.Text

// Creates a new NumberFormatinfo.
var myNfi : NumberFormatInfo = new NumberFormatInfo()

// Takes a long value.
var myInt : long = 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 = [2, 3, 4]
Console.WriteLine("Grouping ( {0} )\t:\t{1}", PrintArraySet(myNfi.NumberGroupSizes), myInt.ToString("N", myNfi))

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


function PrintArraySet(myArr : int[]) : String{
  var myStr : StringBuilder = new StringBuilder()
  myStr.Append(myArr[0].ToString())
  for(var i = 1; i < myArr.Length; i++){
      myStr.Append(", " + myArr[i].ToString())
  }
  return myStr.ToString()
}

// 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 

플랫폼

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

.NET Framework에서 모든 플래폼의 모든 버전을 지원하지는 않습니다. 지원되는 버전의 목록은 시스템 요구 사항을 참조하십시오.

버전 정보

.NET Framework

2.0, 1.1, 1.0에서 지원

.NET Compact Framework

2.0, 1.0에서 지원

참고 항목

참조

NumberFormatInfo 클래스
NumberFormatInfo 멤버
System.Globalization 네임스페이스
NumberFormatInfo.NumberDecimalDigits 속성
NumberFormatInfo.NumberDecimalSeparator 속성
NumberFormatInfo.NumberGroupSeparator 속성
NumberFormatInfo.NaNSymbol 속성
NumberNegativePattern
NumberFormatInfo.CurrencyGroupSizes 속성
PercentGroupSizes