Single.ToString メソッド

定義

このインスタンスの数値を、それと等価な文字列形式に変換します。

オーバーロード

ToString()

このインスタンスの数値を、それと等価な文字列形式に変換します。

ToString(IFormatProvider)

このインスタンスの数値を、指定したカルチャ固有の書式情報を使用して、それと等価な文字列形式に変換します。

ToString(String)

指定した書式を使用して、このインスタンスの数値を、それと等価な文字列形式に変換します。

ToString(String, IFormatProvider)

このインスタンスの数値を、指定した書式およびカルチャ固有の書式情報を使用して、それと等価な文字列形式に変換します。

ToString()

このインスタンスの数値を、それと等価な文字列形式に変換します。

public:
 override System::String ^ ToString();
public override string ToString ();
override this.ToString : unit -> string
Public Overrides Function ToString () As String

戻り値

このインスタンスの値の文字列形式。

次の例では、既定 Single.ToString のメソッドを使用して、複数 Single の値の文字列表現を表示します。

float number;

number = 1.6E20F;
// Displays 1.6E+20.
Console.WriteLine(number.ToString());

number = 1.6E2F;
// Displays 160.
Console.WriteLine(number.ToString());

number = -3.541F;
// Displays -3.541.
Console.WriteLine(number.ToString());

number = -1502345222199E-07F;
// Displays -150234.5222199.
Console.WriteLine(number.ToString());

number = -15023452221990199574E-09F;
// Displays -15023452221.9902.
Console.WriteLine(number.ToString());

number = .60344F;
// Displays 0.60344.
Console.WriteLine(number.ToString());

number = .000000001F;
// Displays 1E-09.
Console.WriteLine(number.ToString());
let number = 1.6E20F
// Displays 1.6E+20.
printfn $"{number.ToString()}"

let number = 1.6E2F
// Displays 160.
printfn $"{number.ToString()}"

let number = -3.541F
// Displays -3.541.
printfn $"{number.ToString()}"

let number = -1502345222199E-07F
// Displays -150234.5222199.
printfn $"{number.ToString()}"

let number = -15023452221990199574E-09F
// Displays -15023452221.9902.
printfn $"{number.ToString()}"

let number = 0.60344F
// Displays 0.60344.
printfn $"{number.ToString()}"

let number = 0.000000001F
// Displays 1E-09.
printfn $"{number.ToString()}"
Dim number As Single

number = 1.6E20
' Displays 1.6E+20.      
Console.WriteLine(number.ToString())

number = 1.6E2
' Displays 160.
Console.WriteLine(number.ToString())

number = -3.541
' Displays -3.541.
Console.WriteLine(number.ToString())

number = -1502345222199E-07
' Displays -150234.5222199.
Console.WriteLine(number.ToString())

number = -15023452221990199574E-09
' Displays -15023452221.9902.
Console.WriteLine(number.ToString())

number = .60344
' Displays 0.60344.
Console.WriteLine(number.ToString())

number = .000000001
' Displays 1E-09.
Console.WriteLine(number.ToString())

次のコード例は、 メソッドと メソッドの Parse(String) 使用方法を ToString() 示しています。

bool done = false;
String^ inp;
do
{
   Console::Write( "Enter a real number: " );
   inp = Console::ReadLine();
   try
   {
      s = Single::Parse( inp );
      Console::WriteLine( "You entered {0}.", s );
      done = true;
   }
   catch ( FormatException^ ) 
   {
      Console::WriteLine( "You did not enter a number." );
   }
   catch ( Exception^ e ) 
   {
      Console::WriteLine( "An exception occurred while parsing your response: {0}", e );
   }
}
while (  !done );
bool done = false;
string inp;
do
{
    Console.Write("Enter a real number: ");
    inp = Console.ReadLine();
    try
    {
        s = Single.Parse(inp);
        Console.WriteLine("You entered {0}.", s.ToString());
        done = true;
    }
    catch (FormatException)
    {
        Console.WriteLine("You did not enter a number.");
    }
    catch (Exception e)
    {
        Console.WriteLine("An exception occurred while parsing your response: {0}", e.ToString());
    }
} while (!done);
let mutable finished = false
while not finished do
    printf "Enter a real number: "
    let inp = stdin.ReadLine()
    try
        let s = Single.Parse inp
        printfn $"You entered {s}."
        finished <- true
    with 
    | :? FormatException ->
        printfn "You did not enter a number."
    | e ->
        printfn "An exception occurred while parsing your response: {e}"
Dim Done As Boolean = False
Dim Inp As String
Do

    Console.Write("Enter a real number: ")
    Inp = Console.ReadLine()
    Try
        S = Single.Parse(Inp)
        Console.WriteLine("You entered " + S.ToString() + ".")
        Done = True
    Catch E As FormatException
        Console.WriteLine("You did not enter a number.")
    Catch E As Exception
        Console.WriteLine("An exception occurred while parsing your response: " + E.ToString())
    End Try
Loop While Not Done

注釈

メソッドは ToString() 、現在の Single カルチャの既定の ("G"、または一般) 形式で値の書式を設定します。 別の形式またはカルチャを指定する場合は、次のように メソッドの他のオーバーロードを ToString 使用します。

形式を使用するには カルチャの場合 オーバーロードを使用する
既定の ("G") 形式 特定のカルチャ ToString(IFormatProvider)
特定の形式 既定の (現在の) カルチャ ToString(String)
特定の形式 特定のカルチャ ToString(String, IFormatProvider)

戻り値には PositiveInfinitySymbol、、 NegativeInfinitySymbolNaNSymbol、または形式の文字列を指定できます。

[sign]integral-digits[.[fractional-digits]][e[sign]exponential-digits]

オプションの要素は角かっこ ([ と ]) で囲まれます。 "digits" という用語を含む要素は、0 から 9 までの一連の数値で構成されます。 次の表に、各要素の一覧を示します。

要素 説明
sign 負符号または正符号記号。
整数桁 数値の整数部分を指定する一連の数字。 整数桁は、小数部がある場合は使用できません。
'.' カルチャ固有の小数点記号。
小数部の数字 数値の小数部を指定する一連の数字。
'e' 指数 (指数) 表記を示す小文字の 'e'。
exponential-digits 指数を指定する一連の数字。

戻り値の例としては、"100"、"-123,456,789"、"123.45e+6"、"500"、"3.1416"、"600"、"-0.123"、"-Infinity" があります。

.NET では、以下の書式設定に関するトピックで詳しく説明されている広範な書式設定のサポートが提供されています。

こちらもご覧ください

適用対象

ToString(IFormatProvider)

このインスタンスの数値を、指定したカルチャ固有の書式情報を使用して、それと等価な文字列形式に変換します。

public:
 virtual System::String ^ ToString(IFormatProvider ^ provider);
public:
 System::String ^ ToString(IFormatProvider ^ provider);
public string ToString (IFormatProvider provider);
public string ToString (IFormatProvider? provider);
override this.ToString : IFormatProvider -> string
Public Function ToString (provider As IFormatProvider) As String

パラメーター

provider
IFormatProvider

カルチャ固有の書式情報を提供するオブジェクト。

戻り値

provider で指定された、このインスタンスの値の文字列形式。

実装

次の例では、複数の異なるカルチャを表すオブジェクトを使用してCultureInfo、2 つのSingle値の文字列表現を表示します。

float value;

value = -16325.62015F;
// Display value using the invariant culture.
Console.WriteLine(value.ToString(CultureInfo.InvariantCulture));
// Display value using the en-GB culture.
Console.WriteLine(value.ToString(CultureInfo.CreateSpecificCulture("en-GB")));
// Display value using the de-DE culture.
Console.WriteLine(value.ToString(CultureInfo.CreateSpecificCulture("de-DE")));

value = 16034.125E21F;
// Display value using the invariant culture.
Console.WriteLine(value.ToString(CultureInfo.InvariantCulture));
// Display value using the en-GB culture.
Console.WriteLine(value.ToString(CultureInfo.CreateSpecificCulture("en-GB")));
// Display value using the de-DE culture.
Console.WriteLine(value.ToString(CultureInfo.CreateSpecificCulture("de-DE")));
// This example displays the following output to the console:
//       -16325.62015
//       -16325.62015
//       -16325,62015
//       1.6034125E+25
//       1.6034125E+25
//       1,6034125E+25
let value = -16325.62015F
// Display value using the invariant culture.
printfn $"{value.ToString CultureInfo.InvariantCulture}"
// Display value using the en-GB culture.
printfn $"""{value.ToString(CultureInfo.CreateSpecificCulture "en-GB")}"""
// Display value using the de-DE culture.
printfn $"""{value.ToString(CultureInfo.CreateSpecificCulture "de-DE")}"""

let value = 16034.125E21F
// Display value using the invariant culture.
printfn $"{value.ToString CultureInfo.InvariantCulture}"
// Display value using the en-GB culture.
printfn $"""{value.ToString(CultureInfo.CreateSpecificCulture "en-GB")}"""
// Display value using the de-DE culture.
printfn $"""{value.ToString(CultureInfo.CreateSpecificCulture "de-DE")}"""
// This example displays the following output to the console:
//       -16325.62015
//       -16325.62015
//       -16325,62015
//       1.6034125E+25
//       1.6034125E+25
//       1,6034125E+25
Dim value As Single 

value = -16325.62015
' Display value using the invariant culture.
Console.WriteLine(value.ToString(CultureInfo.InvariantCulture))
' Display value using the en-GB culture.
Console.WriteLine(value.ToString(CultureInfo.CreateSpecificCulture("en-GB")))
' Display value using the de-DE culture.
Console.WriteLine(value.ToString(CultureInfo.CreateSpecificCulture("de-DE")))

value = 16034.125E21
' Display value using the invariant culture.
Console.WriteLine(value.ToString(CultureInfo.InvariantCulture))
' Display value using the en-GB culture.
Console.WriteLine(value.ToString(CultureInfo.CreateSpecificCulture("en-GB")))
' Display value using the de-DE culture.
Console.WriteLine(value.ToString(CultureInfo.CreateSpecificCulture("de-DE")))
' This example displays the following output to the console:
'       -16325.62015
'       -16325.62015
'       -16325,62015
'       1.6034125E+25
'       1.6034125E+25
'       1,6034125E+25

注釈

メソッドは ToString(IFormatProvider)Single 指定したカルチャの既定の ("G"、または一般) 形式で値の書式を設定します。 別の形式または現在のカルチャを指定する場合は、次のように メソッドの他のオーバーロードを ToString 使用します。

形式を使用するには カルチャの場合 オーバーロードを使用する
既定の ("G") 形式 既定の (現在の) カルチャ ToString()
特定の形式 既定の (現在の) カルチャ ToString(String)
特定の形式 特定のカルチャ ToString(String, IFormatProvider)

戻り値には PositiveInfinitySymbol、、 NegativeInfinitySymbolNaNSymbol、または形式の文字列を指定できます。

[sign]integral-digits[.[fractional-digits]][e[sign]exponential-digits]

オプションの要素は角かっこ ([ と ]) で囲まれます。 "digits" という用語を含む要素は、0 から 9 までの一連の数値で構成されます。 次の表に、各要素の一覧を示します。

要素 説明
sign 負符号または正符号記号。
整数桁 数値の整数部分を指定する一連の数字。 整数桁は、小数部がある場合は使用できません。
'.' カルチャ固有の小数点記号。
小数部の数字 数値の小数部を指定する一連の数字。
'e' 指数 (指数) 表記を示す小文字の 'e'。
exponential-digits 指数を指定する一連の数字。

戻り値の例としては、"100"、"-123,456,789"、"123.45e+6"、"500"、"3.1416"、"600"、"-0.123"、"-Infinity" があります。

.NET では、以下の書式設定に関するトピックで詳しく説明されている広範な書式設定のサポートが提供されています。

パラメーターは provider 、メソッドが IFormatProviderGetFormat オブジェクトを返す実装です NumberFormatInfo 。 通常、 providerCultureInfo オブジェクトまたは オブジェクトです NumberFormatInfo 。 パラメーターは provider 、書式設定で使用されるカルチャ固有の情報を提供します。 が nullの場合provider、戻り値は現在のカルチャのデータをNumberFormatInfo使用して書式設定されます。

指定したカルチャと特定の Single 書式指定文字列を使用して値を文字列表現に変換するには、 メソッドを Single.ToString(String, IFormatProvider) 呼び出します。

こちらもご覧ください

適用対象

ToString(String)

指定した書式を使用して、このインスタンスの数値を、それと等価な文字列形式に変換します。

public:
 System::String ^ ToString(System::String ^ format);
public string ToString (string format);
public string ToString (string? format);
override this.ToString : string -> string
Public Function ToString (format As String) As String

パラメーター

format
String

数値書式指定文字列。

戻り値

format で指定された、このインスタンスの値の文字列形式。

例外

format が無効です。

次の例では、数値を定義し、"C" 標準の数値書式指定文字列を使用して通貨値として書式設定し、"N" 標準の数値書式指定文字列を使用して小数点以下 3 桁の数値として書式設定します。 結果文字列は、en-US カルチャの規則を使用して書式設定されます。 数値書式指定文字列の詳細については、「 標準の数値書式指定文字列 」および「 カスタム数値書式指定文字列」を参照してください。

using System;

public class Example
{
   public static void Main()
   {
      Double number = 1764.3789;
      
      // Format as a currency value.
      Console.WriteLine(number.ToString("C"));
      
      // Format as a numeric value with 3 decimal places.
      Console.WriteLine(number.ToString("N3"));
   }
}
// The example displays the following output:
//       $1,764.38
//       1,764.379
let number = 1764.3789

// Format as a currency value.
printfn $"""{number.ToString "C"}"""

// Format as a numeric value with 3 decimal places.
printfn $"""{number.ToString "N3"}"""
// The example displays the following output:
//       $1,764.38
//       1,764.379
Module Example
   Public Sub Main()
      Dim number As Single = 1764.3789
      
      ' Format as a currency value.
      Console.WriteLine(number.ToString("C"))
      
      ' Format as a numeric value with 3 decimal places.
      Console.WriteLine(number.ToString("N3"))
   End Sub
End Module
' The example displays the following output:
'       $1,764.38
'       1,764.379

次の例では、サポートされている各標準数値書式指定子と 2 つのカスタム数値書式指定文字列を使用して、いくつかの Single 値を表示します。 これらのカスタム書式指定文字列の 1 つは、先頭に 0 を付けて値を Single 埋め込む方法を示しています。 数値を文字列に変換する場合、この例では en-US カルチャの書式設定規則を使用します。

float[] numbers= { 1054.32179F, -195489100.8377F, 1.0437E21F, 
                   -1.0573e-05F };
string[] specifiers = { "C", "E", "e", "F", "G", "N", "P", 
                        "R", "#,000.000", "0.###E-000",
                        "000,000,000,000.00###" };

foreach (float number in numbers)
{
   Console.WriteLine("Formatting of {0}:", number);
   foreach (string specifier in specifiers)
      Console.WriteLine("   {0,5}: {1}", 
                        specifier, number.ToString(specifier));

   Console.WriteLine();
}
// The example displays the following output to the console:
//       Formatting of 1054.32179:
//              C: $1,054.32
//              E: 1.054322E+003
//              e: 1.054322e+003
//              F: 1054.32
//              G: 1054.32179
//              N: 1,054.32
//              P: 105,432.18 %
//              R: 1054.32179
//          #,000.000: 1,054.322
//          0.###E-000: 1.054E003
//          000,000,000,000.00###: 000,000,001,054.322
//       
//       Formatting of -195489100.8377:
//              C: ($195,489,100.84)
//              E: -1.954891E+008
//              e: -1.954891e+008
//              F: -195489100.84
//              G: -195489100.8377
//              N: -195,489,100.84
//              P: -19,548,910,083.77 %
//              R: -195489100.8377
//          #,000.000: -195,489,100.838
//          0.###E-000: -1.955E008
//          000,000,000,000.00###: -000,195,489,100.00
//       
//       Formatting of 1.0437E+21:
//              C: $1,043,700,000,000,000,000,000.00
//              E: 1.043700E+021
//              e: 1.043700e+021
//              F: 1043700000000000000000.00
//              G: 1.0437E+21
//              N: 1,043,700,000,000,000,000,000.00
//              P: 104,370,000,000,000,000,000,000.00 %
//              R: 1.0437E+21
//          #,000.000: 1,043,700,000,000,000,000,000.000
//          0.###E-000: 1.044E021
//          000,000,000,000.00###: 1,043,700,000,000,000,000,000.00
//       
//       Formatting of -1.0573E-05:
//              C: $0.00
//              E: -1.057300E-005
//              e: -1.057300e-005
//              F: 0.00
//              G: -1.0573E-05
//              N: 0.00
//              P: 0.00 %
//              R: -1.0573E-05
//          #,000.000: 000.000
//          0.###E-000: -1.057E-005
//          000,000,000,000.00###: -000,000,000,000.00001
let numbers = 
    [| 1054.32179F; -195489100.8377F; 1.0437E21F; -1.0573e-05F |]
let specifiers = 
    [| "C"; "E"; "e"; "F"; "G"; "N"; "P" 
       "R"; "#,000.000"; "0.###E-000"
       "000,000,000,000.00###" |]

for number in numbers do
    printfn $"Formatting of {number}:"
    for specifier in specifiers do
        printfn $"   {specifier,5}: {number.ToString specifier}" 
    printfn ""
// The example displays the following output to the console:
//       Formatting of 1054.32179:
//              C: $1,054.32
//              E: 1.054322E+003
//              e: 1.054322e+003
//              F: 1054.32
//              G: 1054.32179
//              N: 1,054.32
//              P: 105,432.18 %
//              R: 1054.32179
//          #,000.000: 1,054.322
//          0.###E-000: 1.054E003
//          000,000,000,000.00###: 000,000,001,054.322
//       
//       Formatting of -195489100.8377:
//              C: ($195,489,100.84)
//              E: -1.954891E+008
//              e: -1.954891e+008
//              F: -195489100.84
//              G: -195489100.8377
//              N: -195,489,100.84
//              P: -19,548,910,083.77 %
//              R: -195489100.8377
//          #,000.000: -195,489,100.838
//          0.###E-000: -1.955E008
//          000,000,000,000.00###: -000,195,489,100.00
//       
//       Formatting of 1.0437E+21:
//              C: $1,043,700,000,000,000,000,000.00
//              E: 1.043700E+021
//              e: 1.043700e+021
//              F: 1043700000000000000000.00
//              G: 1.0437E+21
//              N: 1,043,700,000,000,000,000,000.00
//              P: 104,370,000,000,000,000,000,000.00 %
//              R: 1.0437E+21
//          #,000.000: 1,043,700,000,000,000,000,000.000
//          0.###E-000: 1.044E021
//          000,000,000,000.00###: 1,043,700,000,000,000,000,000.00
//       
//       Formatting of -1.0573E-05:
//              C: $0.00
//              E: -1.057300E-005
//              e: -1.057300e-005
//              F: 0.00
//              G: -1.0573E-05
//              N: 0.00
//              P: 0.00 %
//              R: -1.0573E-05
//          #,000.000: 000.000
//          0.###E-000: -1.057E-005
//          000,000,000,000.00###: -000,000,000,000.00001
Dim numbers() As Single = {1054.32179, -195489100.8377, 1.0437E21, _
                           -1.0573e-05}
Dim specifiers() As String = { "C", "E", "e", "F", "G", "N", "P", _
                               "R", "#,000.000", "0.###E-000", _
                               "000,000,000,000.00###"}
For Each number As Single In numbers
   Console.WriteLine("Formatting of {0}:", number)
   For Each specifier As String In specifiers
      Console.WriteLine("   {0,5}: {1}", _
                        specifier, number.ToString(specifier))
   Next
   Console.WriteLine()
Next
' The example displays the following output to the console:
'       Formatting of 1054.32179:
'              C: $1,054.32
'              E: 1.054322E+003
'              e: 1.054322e+003
'              F: 1054.32
'              G: 1054.32179
'              N: 1,054.32
'              P: 105,432.18 %
'              R: 1054.32179
'          #,000.000: 1,054.322
'          0.###E-000: 1.054E003
'          000,000,000,000.00###: 000,000,001,054.322      
'       
'       Formatting of -195489100.8377:
'              C: ($195,489,100.84)
'              E: -1.954891E+008
'              e: -1.954891e+008
'              F: -195489100.84
'              G: -195489100.8377
'              N: -195,489,100.84
'              P: -19,548,910,083.77 %
'              R: -195489100.8377
'          #,000.000: -195,489,100.838
'          0.###E-000: -1.955E008
'          000,000,000,000.00###: -000,195,489,100.00
'       
'       Formatting of 1.0437E+21:
'              C: $1,043,700,000,000,000,000,000.00
'              E: 1.043700E+021
'              e: 1.043700e+021
'              F: 1043700000000000000000.00
'              G: 1.0437E+21
'              N: 1,043,700,000,000,000,000,000.00
'              P: 104,370,000,000,000,000,000,000.00 %
'              R: 1.0437E+21
'          #,000.000: 1,043,700,000,000,000,000,000.000
'          0.###E-000: 1.044E021
'          000,000,000,000.00###: 1,043,700,000,000,000,000,000.00
'       
'       Formatting of -1.0573E-05:
'              C: $0.00
'              E: -1.057300E-005
'              e: -1.057300e-005
'              F: 0.00
'              G: -1.0573E-05
'              N: 0.00
'              P: 0.00 %
'              R: -1.0573E-05
'          #,000.000: 000.000
'          0.###E-000: -1.057E-005
'          000,000,000,000.00###: -000,000,000,000.00001

注釈

メソッドは ToString(String) 、現在の Single カルチャの規則を使用して、指定した形式で値を書式設定します。 既定の ("G"、または一般的な) 形式を使用する場合、または別のカルチャを指定する場合は、次のように メソッドの他のオーバーロードを ToString 使用します。

形式を使用するには カルチャの場合 オーバーロードを使用する
既定の ("G") 形式 既定の (現在の) カルチャ ToString()
既定の ("G") 形式 特定のカルチャ ToString(IFormatProvider)
特定の形式 特定のカルチャ ToString(String, IFormatProvider)

戻り値には、 PositiveInfinitySymbolNegativeInfinitySymbolNaNSymbol、または で指定された現在のインスタンスの値の文字列表現を format指定できます。

パラメーターには format 、D と X を除く任意の有効な標準数値書式指定子と、カスタム数値書式指定子の任意の組み合わせを指定できます。 format が null または空の文字列の場合、戻り値は一般的な数値書式指定子 ("G") で書式設定されます。

.NET では、以下の書式設定に関するトピックで詳しく説明されている広範な書式設定のサポートが提供されています。

既定では、戻り値には 7 桁の有効桁数のみが含まれますが、内部では最大 9 桁が保持されます。 このインスタンスの値が 7 桁を超える場合は、ToString(String)期待される数値の代わりに または NegativeInfinitySymbol を返PositiveInfinitySymbolします。 より多くの有効桁数が必要な場合は、常に 9 桁の有効桁数を返す "G9" 書式指定で を指定します。"R" を指定 format すると、その有効桁数で数値を表すことができる場合は 7 桁、最大有効桁数でのみ数値を表すことができる場合は 9 桁が返されます。

こちらもご覧ください

適用対象

ToString(String, IFormatProvider)

このインスタンスの数値を、指定した書式およびカルチャ固有の書式情報を使用して、それと等価な文字列形式に変換します。

public:
 virtual System::String ^ ToString(System::String ^ format, IFormatProvider ^ provider);
public string ToString (string format, IFormatProvider provider);
public string ToString (string? format, IFormatProvider? provider);
override this.ToString : string * IFormatProvider -> string
Public Function ToString (format As String, provider As IFormatProvider) As String

パラメーター

format
String

数値書式指定文字列。

provider
IFormatProvider

カルチャ固有の書式情報を提供するオブジェクト。

戻り値

format および provider で指定された、このインスタンスの値の文字列形式。

実装

次の例では、 Single 複数の異なるカルチャでサポートされている各標準数値書式指定子を使用して値を表示します。

float value = 16325.62901F;
string specifier;
CultureInfo culture;

// Use standard numeric format specifiers.
specifier = "G";
culture = CultureInfo.CreateSpecificCulture("eu-ES");
Console.WriteLine(value.ToString(specifier, culture));
// Displays:    16325,62901
Console.WriteLine(value.ToString(specifier, CultureInfo.InvariantCulture));
// Displays:    16325.62901

specifier = "C";
culture = CultureInfo.CreateSpecificCulture("en-US");
Console.WriteLine(value.ToString(specifier, culture));
// Displays:    $16,325.63
culture = CultureInfo.CreateSpecificCulture("en-GB");
Console.WriteLine(value.ToString(specifier, culture));
// Displays:    £16,325.63

specifier = "E04";
culture = CultureInfo.CreateSpecificCulture("sv-SE");
Console.WriteLine(value.ToString(specifier, culture));
// Displays: 1,6326E+004   
 culture = CultureInfo.CreateSpecificCulture("en-NZ");
 Console.WriteLine(value.ToString(specifier, culture));
// Displays:    1.6326E+004   

specifier = "F";
culture = CultureInfo.CreateSpecificCulture("fr-FR");
Console.WriteLine(value.ToString(specifier, culture));
// Displays:    16325,63
culture = CultureInfo.CreateSpecificCulture("en-CA");
Console.WriteLine(value.ToString(specifier, culture));
// Displays:    16325.63

specifier = "N";
culture = CultureInfo.CreateSpecificCulture("es-ES");
Console.WriteLine(value.ToString(specifier, culture));
// Displays:    16.325,63
culture = CultureInfo.CreateSpecificCulture("fr-CA");
Console.WriteLine(value.ToString(specifier, culture));
// Displays:    16 325,63

specifier = "P";
culture = CultureInfo.InvariantCulture;
Console.WriteLine((value/10000).ToString(specifier, culture));
// Displays:    163.26 %
culture = CultureInfo.CreateSpecificCulture("ar-EG");
Console.WriteLine((value/10000).ToString(specifier, culture));
// Displays:    163.256 %
let value = 16325.62901F

// Use standard numeric format specifiers.
let specifier = "G"
let culture = CultureInfo.CreateSpecificCulture "eu-ES"
printfn $"{value.ToString(specifier, culture)}"
// Displays:    16325,62901
printfn $"{value.ToString(specifier, CultureInfo.InvariantCulture)}"
// Displays:    16325.62901

let specifier = "C"
let culture = CultureInfo.CreateSpecificCulture "en-US"
printfn $"{value.ToString(specifier, culture)}"
// Displays:    $16,325.63
let culture = CultureInfo.CreateSpecificCulture "en-GB"
printfn $"{value.ToString(specifier, culture)}"
// Displays:    £16,325.63

let specifier = "E04"
let culture = CultureInfo.CreateSpecificCulture "sv-SE"
printfn $"{value.ToString(specifier, culture)}"
// Displays: 1,6326E+004   
let culture = CultureInfo.CreateSpecificCulture "en-NZ"
printfn $"{value.ToString(specifier, culture)}"
// Displays:    1.6326E+004   

let specifier = "F"
let culture = CultureInfo.CreateSpecificCulture "fr-FR"
printfn $"{value.ToString(specifier, culture)}"
// Displays:    16325,63
let culture = CultureInfo.CreateSpecificCulture "en-CA"
printfn $"{value.ToString(specifier, culture)}"
// Displays:    16325.63

let specifier = "N"
let culture = CultureInfo.CreateSpecificCulture "es-ES"
printfn $"{value.ToString(specifier, culture)}"
// Displays:    16.325,63
let culture = CultureInfo.CreateSpecificCulture "fr-CA"
printfn $"{value.ToString(specifier, culture)}"
// Displays:    16 325,63

let specifier = "P"
let culture = CultureInfo.InvariantCulture
printfn $"{(value / 10000f).ToString(specifier, culture)}"
// Displays:    163.26 %
let culture = CultureInfo.CreateSpecificCulture "ar-EG"
printfn $"{(value / 10000f).ToString(specifier, culture)}"
// Displays:    163.256 %
Dim value As Single = 16325.62901
Dim specifier As String
Dim culture As CultureInfo

' Use standard numeric format specifiers.
specifier = "G"
culture = CultureInfo.CreateSpecificCulture("eu-ES")
Console.WriteLine(value.ToString(specifier, culture))
' Displays:    16325,62901
Console.WriteLine(value.ToString(specifier, CultureInfo.InvariantCulture))
' Displays:    16325.62901

specifier = "C"
culture = CultureInfo.CreateSpecificCulture("en-US")
Console.WriteLine(value.ToString(specifier, culture))
' Displays:    $16,325.63
culture = CultureInfo.CreateSpecificCulture("en-GB")
Console.WriteLine(value.ToString(specifier, culture))
' Displays:    £16,325.63

specifier = "E04"
culture = CultureInfo.CreateSpecificCulture("sv-SE")
Console.WriteLine(value.ToString(specifier, culture))
' Displays: 1,6326E+004   
 culture = CultureInfo.CreateSpecificCulture("en-NZ")
 Console.WriteLine(value.ToString(specifier, culture))
' Displays:    1.6326E+004   

specifier = "F"
culture = CultureInfo.CreateSpecificCulture("fr-FR")
Console.WriteLine(value.ToString(specifier, culture))
' Displays:    16325,63
culture = CultureInfo.CreateSpecificCulture("en-CA")
Console.WriteLine(value.ToString(specifier, culture))
' Displays:    16325.63

specifier = "N"
culture = CultureInfo.CreateSpecificCulture("es-ES")
Console.WriteLine(value.ToString(specifier, culture))
' Displays:    16.325,63
culture = CultureInfo.CreateSpecificCulture("fr-CA")
Console.WriteLine(value.ToString(specifier, culture))
' Displays:    16 325,63

specifier = "P"
culture = CultureInfo.InvariantCulture
Console.WriteLine((value/10000).ToString(specifier, culture))
' Displays:    163.26 %
culture = CultureInfo.CreateSpecificCulture("ar-EG")
Console.WriteLine((value/10000).ToString(specifier, culture))
' Displays:    163.256 %

注釈

メソッドは ToString(String, IFormatProvider)Single 指定したカルチャの指定した形式で値の書式を設定します。 既定の形式またはカルチャ設定を使用する場合は、次のように メソッドの他のオーバーロードを ToString 使用します。

形式を使用するには カルチャの場合 オーバーロードを使用する
既定の ("G") 形式 既定の (現在の) カルチャ ToString()
既定の ("G") 形式 特定のカルチャ ToString(IFormatProvider)
特定の形式 既定の (現在の) カルチャ ToString(String)

戻り値には、 PositiveInfinitySymbolNegativeInfinitySymbolNaNSymbol、または で指定された現在のインスタンスの値の文字列表現を format指定できます。

パラメーターには format 、D と X を除く任意の有効な標準数値書式指定子と、カスタム数値書式指定子の任意の組み合わせを指定できます。 が null または空の文字列の場合format、このインスタンスの戻り値は、一般的な数値書式指定子 ("G") で書式設定されます。

.NET では、以下の書式設定に関するトピックで詳しく説明されている広範な書式設定のサポートが提供されています。

パラメーターは provider 、メソッドが IFormatProviderGetFormat オブジェクトを返す実装です NumberFormatInfo 。 通常、 providerCultureInfo オブジェクトまたは オブジェクトです NumberFormatInfo 。 パラメーターは provider 、書式設定で使用されるカルチャ固有の情報を提供します。 が nullの場合provider、戻り値は現在のカルチャの NumberFormatInfo オブジェクトで書式設定されます。

既定では、戻り値には 7 桁の有効桁数のみが含まれますが、内部では最大 9 桁が保持されます。 このインスタンスの値が 7 桁を超える場合は、ToString期待される数値の代わりに または NegativeInfinitySymbol を返PositiveInfinitySymbolします。 より多くの有効桁数が必要な場合は、常に 9 桁の有効桁数を返す "G9" 書式指定で を指定します。"R" を指定 format すると、その有効桁数で数値を表すことができる場合は 7 桁、最大有効桁数でのみ数値を表すことができる場合は 9 桁が返されます。

こちらもご覧ください

適用対象