NumberFormatInfoとは? わかりやすく解説

NumberFormatInfo クラス

カルチャに応じて、数値を形式指定および表示する方法を定義します。

名前空間: System.Globalization
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

<SerializableAttribute> _
<ComVisibleAttribute(True)> _
Public NotInheritable Class
 NumberFormatInfo
    Implements ICloneable, IFormatProvider
Dim instance As NumberFormatInfo
[SerializableAttribute] 
[ComVisibleAttribute(true)] 
public sealed class NumberFormatInfo : ICloneable,
 IFormatProvider
[SerializableAttribute] 
[ComVisibleAttribute(true)] 
public ref class NumberFormatInfo sealed :
 ICloneable, IFormatProvider
/** @attribute SerializableAttribute() */ 
/** @attribute ComVisibleAttribute(true) */ 
public final class NumberFormatInfo implements
 ICloneable, IFormatProvider
SerializableAttribute 
ComVisibleAttribute(true) 
public final class NumberFormatInfo implements
 ICloneable, IFormatProvider
解説解説

このクラスは、通貨、桁区切り記号、その他の数値記号などの情報を格納します。

特定のカルチャの NumberFormatInfo を作成するには、そのカルチャの CultureInfo を作成し、CultureInfo.NumberFormat プロパティを取得します。現在のスレッドのカルチャに対して NumberFormatInfo を作成するには、CurrentInfo プロパティを使用します。インバリアント カルチャの NumberFormatInfo を作成するには、読み取り専用バージョンでは InvariantInfo プロパティを使用し、書き込み可能バージョンでは NumberFormatInfo コンストラクタを使用します。ニュートラル カルチャの NumberFormatInfo は作成できません。

ユーザーは、[コントロール パネル] の [地域と言語のオプション] (オペレーティング システムによっては [地域のオプション] または [地域]) を使用して、Windows の現在のカルチャに関連付けられた値の一部をオーバーライドすることもできます。たとえば、ユーザーが別の形式で日付を表示したり、カルチャの既定の通貨以外の通貨を使用したりすることを選択する場合があります。CultureInfo.UseUserOverride プロパティが true に設定されている場合は、CultureInfo.DateTimeFormat、CultureInfo.NumberFormat、CultureInfo.TextInfo の各インスタンスのプロパティもユーザー設定から取得されます。ユーザー設定と CultureInfo に関連付けられたカルチャとの間に互換性がない場合 (たとえば、選択されたカレンダーが OptionalCalendars のいずれかでない場合)、メソッドの結果およびプロパティの値は未定義です。

数値は、NumberFormatInfo のプロパティに格納されている標準パターンまたはカスタム パターンを使用して、形式指定します。値を表示する方法を変更するには、カスタム パターンをプロパティに保存するために、NumberFormatInfo を書き込み可能にする必要があります。

各標準パターンの標準形式指定文字と、設定して標準パターンを変更できる関連付けられた NumberFormatInfo プロパティを次の表に示します。

書式指定文字

説明および関連付けられたプロパティ

c, C

通貨書式。 CurrencyNegativePattern, CurrencyPositivePattern, CurrencySymbol, CurrencyGroupSizes, CurrencyGroupSeparator, CurrencyDecimalDigits, CurrencyDecimalSeparator.

d, D

Decimal 形式。

e, E

Scientific (指数) 形式。

f, F

Fixed-point 形式。

g, G

General 形式。

n, N

Number 形式。 NumberNegativePattern, NumberGroupSizes, NumberGroupSeparator, NumberDecimalDigits, NumberDecimalSeparator.

r, R

Roundtrip 形式。この形式では、文字列に変換された数値は、数値に再変換したときに同じ値になります。

x, X

Hexadecimal 形式。

ニュートラル カルチャを除くインバリアント カルチャまたは特定のカルチャに対してだけ、DateTimeFormatInfo または NumberFormatInfo を作成できます。インバリアント カルチャ、特定のカルチャ、およびニュートラル カルチャの詳細については、CultureInfo クラスのトピックを参照してください。

このクラスは、NumberFormatInfo オブジェクトを複製できるようにする ICloneable インターフェイスを実装します。アプリケーションに形式指定情報を提供するために、IFormatProvider も実装します。

使用例使用例

対応する CultureInfo の NumberFormatInfo を取得し、その NumberFormatInfo を使用してそのカルチャの数値形式指定情報を問い合わせる方法を次のコード例に示します。

using System;
using System.Globalization;
using System.Text;

public sealed class App 
{
    static void Main() 
    {
        StringBuilder sb = new StringBuilder();

        // Loop through all the specific cultures known to the CLR.
        foreach (CultureInfo ci in CultureInfo.GetCultures(CultureTypes.SpecificCultures))
 
        {
            // Only show the currency symbols for cultures that speak
 English.
            if (ci.TwoLetterISOLanguageName != "en")
 continue;
             
            // Display the culture name and currency symbol.
            NumberFormatInfo nfi = ci.NumberFormat;
            sb.AppendFormat("The currency symbol for '{0}'
 is '{1}'",
                ci.DisplayName, nfi.CurrencySymbol);
            sb.AppendLine();
        }
        Console.WriteLine(sb.ToString());
    }
}

// This code produces the following output.
//
// The currency symbol for 'English (United States)' is '$'
// The currency symbol for 'English (United Kingdom)' is ''
// The currency symbol for 'English (Australia)' is '$'
// The currency symbol for 'English (Canada)' is '$'
// The currency symbol for 'English (New Zealand)' is '$'
// The currency symbol for 'English (Ireland)' is '?'
// The currency symbol for 'English (South Africa)' is 'R'
// The currency symbol for 'English (Jamaica)' is 'J$'
// The currency symbol for 'English (Caribbean)' is '$'
// The currency symbol for 'English (Belize)' is 'BZ$'
// The currency symbol for 'English (Trinidad and Tobago)' is 'TT$'
// The currency symbol for 'English (Zimbabwe)' is 'Z$'
// The currency symbol for 'English (Republic of the Philippines)' is
 'Php'
using namespace System;
using namespace System::Globalization;
using namespace System::Text;

int main()
{
    StringBuilder^ builder = gcnew StringBuilder();

    // Loop through all the specific cultures known to the CLR.
    for each(CultureInfo^ culture in 
        CultureInfo::GetCultures (CultureTypes::SpecificCultures)) 
    {
        // Only show the currency symbols for cultures 
        // that speak English.
        if (culture->TwoLetterISOLanguageName == "en")
        {
            // Display the culture name and currency symbol.
            NumberFormatInfo^ numberFormat = culture->NumberFormat;
            builder->AppendFormat("The currency symbol for
 '{0}'"+
                "is '{1}'",culture->DisplayName,
                numberFormat->CurrencySymbol);
            builder->AppendLine();
        }
    }
    Console::WriteLine(builder);
}

// This code produces the following output.
//
// The currency symbol for 'English (United States)' is '$'
// The currency symbol for 'English (United Kingdom)' is 'Ј'
// The currency symbol for 'English (Australia)' is '$'
// The currency symbol for 'English (Canada)' is '$'
// The currency symbol for 'English (New Zealand)' is '$'
// The currency symbol for 'English (Ireland)' is '?'
// The currency symbol for 'English (South Africa)' is 'R'
// The currency symbol for 'English (Jamaica)' is 'J$'
// The currency symbol for 'English (Caribbean)' is '$'
// The currency symbol for 'English (Belize)' is 'BZ$'
// The currency symbol for 'English (Trinidad and Tobago)' is 'TT$'
// The currency symbol for 'English (Zimbabwe)' is 'Z$'
// The currency symbol for 'English (Republic of the Philippines)' is
 'Php'
継承階層継承階層
System.Object
  System.Globalization.NumberFormatInfo
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバの場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

NumberFormatInfo コンストラクタ


NumberFormatInfo プロパティ


パブリック プロパティパブリック プロパティ

  名前 説明
パブリック プロパティ PositiveSign 関連付けられた数値が正であることを示す文字列を取得または設定します。
参照参照

関連項目

NumberFormatInfo クラス
System.Globalization 名前空間
Decimal
CultureInfo クラス

その他の技術情報

書式設定の概要

NumberFormatInfo メソッド


NumberFormatInfo メンバ

カルチャに応じて、数値を形式指定および表示する方法を定義します。

NumberFormatInfo データ型で公開されるメンバを以下の表に示します。


パブリック コンストラクタパブリック コンストラクタ
  名前 説明
パブリック メソッド NumberFormatInfo カルチャに依存しない (インバリアントな) NumberFormatInfo クラスの新しい書き込み可能インスタンスを初期化します。
パブリック プロパティパブリック プロパティ
  名前 説明
パブリック プロパティ PositiveSign 関連付けられた数値が正であることを示す文字列を取得または設定します。
パブリック メソッドパブリック メソッド
参照参照

関連項目

NumberFormatInfo クラス
System.Globalization 名前空間
Decimal
CultureInfo クラス

その他の技術情報

書式設定の概要



英和和英テキスト翻訳

英語⇒日本語日本語⇒英語

辞書ショートカット

すべての辞書の索引

「NumberFormatInfo」の関連用語

NumberFormatInfoのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



NumberFormatInfoのページの著作権

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2026 Microsoft.All rights reserved.

©2026 GRAS Group, Inc.RSS