Share via


CultureInfo.NumberFormat プロパティ

数値、通貨、および割合を表示するカルチャに対応する書式を定義する NumberFormatInfo を取得または設定します。

Public Overridable Property NumberFormat As NumberFormatInfo
[C#]
public virtual NumberFormatInfo NumberFormat {get; set;}
[C++]
public: __property virtual NumberFormatInfo* get_NumberFormat();public: __property virtual void set_NumberFormat(NumberFormatInfo*);
[JScript]
public function get NumberFormat() : NumberFormatInfo;public function set NumberFormat(NumberFormatInfo);

プロパティ値

数値、通貨、および割合を表示するカルチャに対応する書式を定義する NumberFormatInfo

例外

例外の種類 条件
ArgumentNullException プロパティが null 参照 (Visual Basic では Nothing) に設定されています。
NotSupportedException CultureInfo は、ニュートラル カルチャ用です。
InvalidOperationException NumberFormat プロパティまたは NumberFormatInfo の任意のプロパティが設定されます。 CultureInfo は読み取り専用です。

解説

ニュートラル カルチャを除くインバリアント カルチャまたは特定のカルチャに対してだけ、 NumberFormatInfo を作成できます。

カルチャは、通常、インバリアント カルチャ、ニュートラル カルチャ、および特定カルチャの 3 つのセットにグループ化されます。

インバリアント カルチャは、カルチャ固有の設定ではありません。空の文字列 ("") を使用した名前で、またはカルチャ識別子 0x007F を使用することによって、インバリアント カルチャを指定できます。 InvariantCulture は、インバリアント カルチャのインスタンスを取得します。この設定は、英語と関連付けられていますが、国や地域には関連付けられていません。これは、カルチャを必要とする Globalization 名前空間のほとんどのメソッドで使用できます。セキュリティの決定が文字列の比較や大文字/小文字の変換操作に依存する場合は、システムのカルチャ設定にかかわらず一定の動作を保証するために InvariantCulture を使用してください。ただし、インバリアント カルチャは、システム サービスなど、カルチャに依存しない結果を必要とするプロセスでだけ使用する必要があります。それ以外の場合に使用すると、言語として正しくない、またはカルチャに対して不適切な結果が生じます。

ニュートラル カルチャは、国や地域ではなく、言語に関連付けられているカルチャです。特定のカルチャは、1 つの言語、および 1 つの国または地域に関連付けられたカルチャです。たとえば、"fr" はニュートラル カルチャであり、"fr-FR" は特定のカルチャです。"zh-CHS" (簡体字"zh-CHT"中国語) および "zh-CHT" (繁体字中国語) はニュートラル カルチャです。

ユーザーは、[コントロール パネル] の [地域と言語のオプション] (オペレーティング システムによっては [地域のオプション] または [地域]) を使用して、Windows の現在のカルチャに関連付けられた値の一部をオーバーライドすることもできます。たとえば、ユーザーが別の形式で日付を表示したり、カルチャの既定の通貨以外の通貨を使用したりすることを選択する場合があります。

UseUserOverridetrue であり、指定されたカルチャが Windows の現在のカルチャと一致する場合、 CultureInfo はこれらのオーバーライドを使用します。これには、 DateTimeFormat プロパティによって返される DateTimeFormatInfo インスタンスのプロパティ、 NumberFormat プロパティによって返される NumberFormatInfo インスタンスのプロパティ、および CompareInfo プロパティによって返される CompareInfo インスタンスのプロパティのユーザー設定値が含まれます。ユーザー設定が CultureInfo に関連付けられたカルチャと互換性を持たない場合 (たとえば、選択した暦が OptionalCalendars のいずれでもない場合)、メソッドの結果とプロパティの値は未定義になります。

使用例

[Visual Basic, C#, C++] CultureInfo.Clone が CultureInfo に関連付けられている DateTimeFormatInfo インスタンスと NumberFormatInfo インスタンスのクローンも作成するコードの例を次に示します。

 
Imports System
Imports System.Globalization


Public Class SamplesCultureInfo
   
   Public Shared Sub Main()
      
      ' Creates and initializes a CultureInfo.
      Dim myCI As New CultureInfo("en-US", False)
      
      ' Clones myCI and modifies the DTFI and NFI instances associated with the clone.
      Dim myCIclone As CultureInfo = CType(myCI.Clone(), CultureInfo)
      myCIclone.DateTimeFormat.AMDesignator = "a.m."
      myCIclone.DateTimeFormat.DateSeparator = "-"
      myCIclone.NumberFormat.CurrencySymbol = "USD"
      myCIclone.NumberFormat.NumberDecimalDigits = 4
      
      ' Displays the properties of the DTFI and NFI instances associated with the original and with the clone. 
      Console.WriteLine("DTFI/NFI PROPERTY" + ControlChars.Tab + "ORIGINAL" + ControlChars.Tab + "MODIFIED CLONE")
      Console.WriteLine("DTFI.AMDesignator" + ControlChars.Tab + "{0}" + ControlChars.Tab + ControlChars.Tab + "{1}", myCI.DateTimeFormat.AMDesignator, myCIclone.DateTimeFormat.AMDesignator)
      Console.WriteLine("DTFI.DateSeparator" + ControlChars.Tab + "{0}" + ControlChars.Tab + ControlChars.Tab + "{1}", myCI.DateTimeFormat.DateSeparator, myCIclone.DateTimeFormat.DateSeparator)
      Console.WriteLine("NFI.CurrencySymbol" + ControlChars.Tab + "{0}" + ControlChars.Tab + ControlChars.Tab + "{1}", myCI.NumberFormat.CurrencySymbol, myCIclone.NumberFormat.CurrencySymbol)
      Console.WriteLine("NFI.NumberDecimalDigits" + ControlChars.Tab + "{0}" + ControlChars.Tab + ControlChars.Tab + "{1}", myCI.NumberFormat.NumberDecimalDigits, myCIclone.NumberFormat.NumberDecimalDigits)

   End Sub 'Main 

End Class 'SamplesCultureInfo


' This code produces the following output.
'
' DTFI/NFI PROPERTY       ORIGINAL        MODIFIED CLONE
' DTFI.AMDesignator       AM              a.m.
' DTFI.DateSeparator      /               -
' NFI.CurrencySymbol      $               USD
' NFI.NumberDecimalDigits 2               4

[C#] 
using System;
using System.Globalization;


public class SamplesCultureInfo  {

   public static void Main()  {

      // Creates and initializes a CultureInfo.
      CultureInfo myCI = new CultureInfo("en-US", false);

      // Clones myCI and modifies the DTFI and NFI instances associated with the clone.
      CultureInfo myCIclone = (CultureInfo) myCI.Clone();
      myCIclone.DateTimeFormat.AMDesignator = "a.m.";
      myCIclone.DateTimeFormat.DateSeparator = "-";
      myCIclone.NumberFormat.CurrencySymbol = "USD";
      myCIclone.NumberFormat.NumberDecimalDigits = 4;

      // Displays the properties of the DTFI and NFI instances associated with the original and with the clone. 
      Console.WriteLine( "DTFI/NFI PROPERTY\tORIGINAL\tMODIFIED CLONE" );
      Console.WriteLine( "DTFI.AMDesignator\t{0}\t\t{1}", myCI.DateTimeFormat.AMDesignator, myCIclone.DateTimeFormat.AMDesignator );
      Console.WriteLine( "DTFI.DateSeparator\t{0}\t\t{1}", myCI.DateTimeFormat.DateSeparator, myCIclone.DateTimeFormat.DateSeparator );
      Console.WriteLine( "NFI.CurrencySymbol\t{0}\t\t{1}", myCI.NumberFormat.CurrencySymbol, myCIclone.NumberFormat.CurrencySymbol );
      Console.WriteLine( "NFI.NumberDecimalDigits\t{0}\t\t{1}", myCI.NumberFormat.NumberDecimalDigits, myCIclone.NumberFormat.NumberDecimalDigits );
      
   }

}

/*
This code produces the following output.

DTFI/NFI PROPERTY       ORIGINAL        MODIFIED CLONE
DTFI.AMDesignator       AM              a.m.
DTFI.DateSeparator      /               -
NFI.CurrencySymbol      $               USD
NFI.NumberDecimalDigits 2               4

*/

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

int main()
{
   // Creates and initializes a CultureInfo.
   CultureInfo* myCI = new CultureInfo(S"en-US", false);

   // Clones myCI and modifies the DTFI and NFI instances associated with the clone.
   CultureInfo * myCIclone = dynamic_cast<CultureInfo*>(myCI -> Clone());
   myCIclone -> DateTimeFormat -> AMDesignator = S"a.m.";
   myCIclone -> DateTimeFormat -> DateSeparator = S"-";
   myCIclone -> NumberFormat -> CurrencySymbol = S"USD";
   myCIclone -> NumberFormat -> NumberDecimalDigits = 4;

   // Displays the properties of the DTFI and NFI instances associated with the original and with the clone. 
   Console::WriteLine(S"DTFI/NFI PROPERTY\tORIGINAL\tMODIFIED CLONE");
   Console::WriteLine(S"DTFI.AMDesignator\t{0}\t\t{1}", myCI -> DateTimeFormat -> AMDesignator, myCIclone -> DateTimeFormat -> AMDesignator);
   Console::WriteLine(S"DTFI.DateSeparator\t{0}\t\t{1}", myCI -> DateTimeFormat -> DateSeparator, myCIclone -> DateTimeFormat -> DateSeparator);
   Console::WriteLine(S"NFI.CurrencySymbol\t{0}\t\t{1}", myCI -> NumberFormat -> CurrencySymbol, myCIclone -> NumberFormat -> CurrencySymbol);
   Console::WriteLine(S"NFI.NumberDecimalDigits\t{0}\t\t{1}", __box(myCI -> NumberFormat -> NumberDecimalDigits), __box(myCIclone -> NumberFormat -> NumberDecimalDigits));
}
/*
This code produces the following output.

DTFI/NFI PROPERTY       ORIGINAL        MODIFIED CLONE
DTFI.AMDesignator       AM              a.m.
DTFI.DateSeparator      /               -
NFI.CurrencySymbol      $               USD
NFI.NumberDecimalDigits 2               4
*/

[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

参照

CultureInfo クラス | CultureInfo メンバ | System.Globalization 名前空間 | NumberFormatInfo | GetFormat | DateTimeFormat