NumberFormatInfo.NumberGroupSeparator プロパティ

数値で小数点の左にある数字のグループを区切る文字列を取得または設定します。

Public Property NumberGroupSeparator As String
[C#]
public string NumberGroupSeparator {get; set;}
[C++]
public: __property String* get_NumberGroupSeparator();public: __property void set_NumberGroupSeparator(String*);
[JScript]
public function get NumberGroupSeparator() : String;public function set NumberGroupSeparator(String);

プロパティ値

数値で小数点の左にある数字のグループを区切る文字列。 InvariantInfo の既定値は "," です。

例外

例外の種類 条件
ArgumentNullException プロパティが null 参照 (Visual Basic では Nothing) に設定されています。
InvalidOperationException プロパティが設定されていますが、 NumberFormatInfo が読み取り専用です。

解説

このプロパティの初期値は、[コントロール パネル] の [地域と言語のオプション] (オペレーティング システムによっては [地域のオプション] または [地域]) の設定から取得されます。ただし、 NumberGroupSeparator または CurrencyGroupSeparatorNumberDecimalSeparator または CurrencyDecimalSeparator と同じ場合、解析中に ArgumentException がスローされます。

使用例

[Visual Basic, C#, C++] NumberGroupSeparator プロパティの変更による影響を次のコード例に示します。

 
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 = 123456789
      Console.WriteLine(myInt.ToString("N", nfi))

      ' Displays the same value with a blank as the separator.
      nfi.NumberGroupSeparator = " "
      Console.WriteLine(myInt.ToString("N", nfi))

   End Sub 'Main 

End Class 'NumberFormatInfoSample


'This code produces the following output.

'

'123,456,789.00

'123 456 789.00



[C#] 
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 = 123456789;
      Console.WriteLine( myInt.ToString( "N", nfi ) );

      // Displays the same value with a blank as the separator.
      nfi.NumberGroupSeparator = " ";
      Console.WriteLine( myInt.ToString( "N", nfi ) );

   }
}


/* 
This code produces the following output.

123,456,789.00
123 456 789.00
*/
   

[C++] 
#using <mscorlib.dll>
using namespace System;
using namespace System::Globalization;

int main()
{
   // Gets a NumberFormatInfo associated with the en-US culture.
   CultureInfo * MyCI = new CultureInfo(S"en-US", false);
   NumberFormatInfo* nfi = MyCI -> NumberFormat;

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

   // Displays the same value with a blank as the separator.
   nfi -> NumberGroupSeparator = S" ";
   Console::WriteLine(myInt.ToString(S"N", nfi));
}
/*
This code produces the following output.
123, 456, 789.00
123 456 789.00
*/

[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

必要条件

プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ, .NET Compact Framework - Windows CE .NET, Common Language Infrastructure (CLI) Standard

参照

NumberFormatInfo クラス | NumberFormatInfo メンバ | System.Globalization 名前空間 | NumberDecimalDigits | NumberDecimalSeparator | NumberGroupSizes | NaNSymbol | NumberNegativePattern | CurrencyGroupSeparator | PercentGroupSeparator