Int32.ToString メソッド
定義
このインスタンスの数値を、それと等価な文字列形式に変換します。Converts the numeric value of this instance to its equivalent string representation.
オーバーロード
ToString(IFormatProvider) |
このインスタンスの数値を、指定したカルチャ固有の書式情報を使用して、それと等価な文字列形式に変換します。Converts the numeric value of this instance to its equivalent string representation using the specified culture-specific format information. |
ToString(String, IFormatProvider) |
このインスタンスの数値を、指定した書式およびカルチャ固有の書式情報を使用して、それと等価な文字列形式に変換します。Converts the numeric value of this instance to its equivalent string representation using the specified format and culture-specific format information. |
ToString(String) |
指定した書式を使用して、このインスタンスの数値を、それと等価な文字列形式に変換します。Converts the numeric value of this instance to its equivalent string representation, using the specified format. |
ToString() |
このインスタンスの数値を、それと等価な文字列形式に変換します。Converts the numeric value of this instance to its equivalent string representation. |
ToString(IFormatProvider)
このインスタンスの数値を、指定したカルチャ固有の書式情報を使用して、それと等価な文字列形式に変換します。Converts the numeric value of this instance to its equivalent string representation using the specified culture-specific format information.
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
カルチャ固有の書式情報を提供するオブジェクト。An object that supplies culture-specific formatting information.
戻り値
provider
で指定された、このインスタンスの値の文字列形式。The string representation of the value of this instance as specified by provider
.
実装
例
次の例では、 Int32 複数の異なるカルチャを表すオブジェクトを使用して、値の文字列形式を表示し CultureInfo ます。The following example displays the string representation of an Int32 value using CultureInfo objects that represent several different cultures.
using namespace System;
using namespace System::Globalization;
void main()
{
int value = -16325;
// 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")));
}
// The example displays the following output:
// -16325
// -16325
// -16325
int value = -16325;
// 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
// -16325
// -16325
Dim value As Integer = -16325
' 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
' -16325
' -16325
注釈
メソッドは、 ToString(IFormatProvider) Int32 NumberFormatInfo 指定されたカルチャのオブジェクトを使用して、既定の ("G" または "general") 形式の値を書式設定します。The ToString(IFormatProvider) method formats an Int32 value in the default ("G", or general) format by using the NumberFormatInfo object of a specified culture. 別の形式または現在のカルチャを指定する場合は、次のようにメソッドの他のオーバーロードを使用し ToString ます。If you want to specify a different format or the current culture, use the other overloads of the ToString method, as follows:
形式を使用するにはTo use format | カルチャの場合For culture | オーバーロードを使用するUse the overload |
---|---|---|
既定 ("G") 形式Default ("G") format | 既定の (現在の) カルチャDefault (current) culture | ToString() |
特定の形式A specific format | 既定の (現在の) カルチャDefault (current) culture | ToString(String) |
特定の形式A specific format | 特定のカルチャA specific culture | ToString(String, IFormatProvider) |
パラメーターは、 provider
インターフェイスを実装するオブジェクトです IFormatProvider 。The provider
parameter is an object that implements the IFormatProvider interface. このメソッドは、 GetFormat NumberFormatInfo このメソッドによって返される文字列の書式に関するカルチャ固有の情報を提供するオブジェクトを返します。Its GetFormat method returns a NumberFormatInfo object that provides culture-specific information about the format of the string that is returned by this method. を実装するオブジェクトは IFormatProvider 、次のいずれかになります。The object that implements IFormatProvider can be any of the following:
CultureInfo書式設定規則を使用するカルチャを表すオブジェクト。A CultureInfo object that represents the culture whose formatting rules are to be used.
NumberFormatInfoこの値の特定の数値書式情報を格納しているオブジェクト。A NumberFormatInfo object that contains specific numeric formatting information for this value.
IFormatProviderを実装し、 GetFormat NumberFormatInfo 書式設定情報を提供するオブジェクトを返すメソッドを持つカスタムオブジェクト。A custom object that implements IFormatProvider and whose GetFormat method returns a NumberFormatInfo object that provides formatting information.
がである provider
null
か、 NumberFormatInfo からオブジェクトを取得できない場合 provider
、戻り値は、 NumberFormatInfo スレッドの現在のカルチャのオブジェクトを使用して書式設定されます。If provider
is null
or a NumberFormatInfo object cannot be obtained from provider
, the return value is formatted using the NumberFormatInfo object for the thread current culture. スレッドの現在のカルチャの詳細については、「」を参照してください Thread.CurrentCulture 。For information about the thread current culture, see Thread.CurrentCulture.
.NET ではさまざまな書式設定がサポートされています。詳細については、次の書式設定に関するトピックを参照してください。.NET provides extensive formatting support, which is described in greater detail in the following formatting topics:
数値書式指定子の詳細については、「 標準の数値書式指定文字列 」および「 カスタム数値書式指定文字列」を参照してください。For more information about numeric format specifiers, see Standard Numeric Format Strings and Custom Numeric Format Strings.
書式設定の詳細については、「 型の書式設定」を参照してください。For more information about formatting, see Formatting Types.
こちらもご覧ください
適用対象
ToString(String, IFormatProvider)
このインスタンスの数値を、指定した書式およびカルチャ固有の書式情報を使用して、それと等価な文字列形式に変換します。Converts the numeric value of this instance to its equivalent string representation using the specified format and culture-specific format information.
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
標準またはカスタムの数値書式指定文字列。A standard or custom numeric format string.
- provider
- IFormatProvider
カルチャ固有の書式情報を提供するオブジェクト。An object that supplies culture-specific formatting information.
戻り値
format
および provider
で指定された、このインスタンスの値の文字列形式。The string representation of the value of this instance as specified by format
and provider
.
実装
例外
format
は使用できないか、またはサポートされていません。format
is invalid or not supported.
例
次の例では、3つの異なるカルチャに対してサポートされている各標準数値書式指定子を使用して、正の値と負の値を表示します。The following example displays a positive and a negative value using each of the supported standard numeric format specifiers for three different cultures.
using namespace System;
using namespace System::Globalization;
void main()
{
// Define cultures whose formatting conventions are to be used.
array<CultureInfo^>^ cultures = { CultureInfo::CreateSpecificCulture("en-US"),
CultureInfo::CreateSpecificCulture("fr-FR"),
CultureInfo::CreateSpecificCulture("es-ES") };
int positiveNumber = 1679;
int negativeNumber = -3045;
array<String^>^ specifiers = {"G", "C", "D8", "E2", "F", "N", "P", "X8"};
for each (String^ specifier in specifiers)
{
for each (CultureInfo^ culture in cultures)
{
// Display values with "G" format specifier.
Console::WriteLine("{0} format using {1} culture: {2, 16} {3, 16}",
specifier, culture->Name,
positiveNumber.ToString(specifier, culture),
negativeNumber.ToString(specifier, culture));
}
Console::WriteLine();
}
}
// The example displays the following output:
// G format using en-US culture: 1679 -3045
// G format using fr-FR culture: 1679 -3045
// G format using es-ES culture: 1679 -3045
//
// C format using en-US culture: $1,679.00 ($3,045.00)
// C format using fr-FR culture: 1 679,00 € -3 045,00 €
// C format using es-ES culture: 1.679,00 € -3.045,00 €
//
// D8 format using en-US culture: 00001679 -00003045
// D8 format using fr-FR culture: 00001679 -00003045
// D8 format using es-ES culture: 00001679 -00003045
//
// E2 format using en-US culture: 1.68E+003 -3.05E+003
// E2 format using fr-FR culture: 1,68E+003 -3,05E+003
// E2 format using es-ES culture: 1,68E+003 -3,05E+003
//
// F format using en-US culture: 1679.00 -3045.00
// F format using fr-FR culture: 1679,00 -3045,00
// F format using es-ES culture: 1679,00 -3045,00
//
// N format using en-US culture: 1,679.00 -3,045.00
// N format using fr-FR culture: 1 679,00 -3 045,00
// N format using es-ES culture: 1.679,00 -3.045,00
//
// P format using en-US culture: 167,900.00 % -304,500.00 %
// P format using fr-FR culture: 167 900,00 % -304 500,00 %
// P format using es-ES culture: 167.900,00 % -304.500,00 %
//
// X8 format using en-US culture: 0000068F FFFFF41B
// X8 format using fr-FR culture: 0000068F FFFFF41B
// X8 format using es-ES culture: 0000068F FFFFF41B
// Define cultures whose formatting conventions are to be used.
CultureInfo[] cultures = {CultureInfo.CreateSpecificCulture("en-US"),
CultureInfo.CreateSpecificCulture("fr-FR"),
CultureInfo.CreateSpecificCulture("es-ES") };
int positiveNumber = 1679;
int negativeNumber = -3045;
string[] specifiers = {"G", "C", "D8", "E2", "F", "N", "P", "X8"};
foreach (string specifier in specifiers)
{
foreach (CultureInfo culture in cultures)
{
// Display values with "G" format specifier.
Console.WriteLine("{0} format using {1} culture: {2, 16} {3, 16}",
specifier, culture.Name,
positiveNumber.ToString(specifier, culture),
negativeNumber.ToString(specifier, culture));
}
Console.WriteLine();
}
// The example displays the following output:
// G format using en-US culture: 1679 -3045
// G format using fr-FR culture: 1679 -3045
// G format using es-ES culture: 1679 -3045
//
// C format using en-US culture: $1,679.00 ($3,045.00)
// C format using fr-FR culture: 1 679,00 € -3 045,00 €
// C format using es-ES culture: 1.679,00 € -3.045,00 €
//
// D8 format using en-US culture: 00001679 -00003045
// D8 format using fr-FR culture: 00001679 -00003045
// D8 format using es-ES culture: 00001679 -00003045
//
// E2 format using en-US culture: 1.68E+003 -3.05E+003
// E2 format using fr-FR culture: 1,68E+003 -3,05E+003
// E2 format using es-ES culture: 1,68E+003 -3,05E+003
//
// F format using en-US culture: 1679.00 -3045.00
// F format using fr-FR culture: 1679,00 -3045,00
// F format using es-ES culture: 1679,00 -3045,00
//
// N format using en-US culture: 1,679.00 -3,045.00
// N format using fr-FR culture: 1 679,00 -3 045,00
// N format using es-ES culture: 1.679,00 -3.045,00
//
// P format using en-US culture: 167,900.00 % -304,500.00 %
// P format using fr-FR culture: 167 900,00 % -304 500,00 %
// P format using es-ES culture: 167.900,00 % -304.500,00 %
//
// X8 format using en-US culture: 0000068F FFFFF41B
// X8 format using fr-FR culture: 0000068F FFFFF41B
// X8 format using es-ES culture: 0000068F FFFFF41B
' Define cultures whose formatting conventions are to be used.
Dim cultures() As CultureInfo = {CultureInfo.CreateSpecificCulture("en-US"), _
CultureInfo.CreateSpecificCulture("fr-FR"), _
CultureInfo.CreateSpecificCulture("es-ES") }
Dim positiveNumber As Integer = 1679
Dim negativeNumber As Integer = -3045
Dim specifiers() As String = {"G", "C", "D8", "E2", "F", "N", "P", "X8"}
For Each specifier As String In specifiers
For Each culture As CultureInfo In Cultures
' Display values with "G" format specifier.
Console.WriteLine("{0} format using {1} culture: {2, 16} {3, 16}", _
specifier, culture.Name, _
positiveNumber.ToString(specifier, culture), _
negativeNumber.ToString(specifier, culture))
Next
Console.WriteLine()
Next
' The example displays the following output to the console:
' G format using en-US culture: 1679 -3045
' G format using fr-FR culture: 1679 -3045
' G format using es-ES culture: 1679 -3045
'
' C format using en-US culture: $1,679.00 ($3,045.00)
' C format using fr-FR culture: 1 679,00 € -3 045,00 €
' C format using es-ES culture: 1.679,00 € -3.045,00 €
'
' D8 format using en-US culture: 00001679 -00003045
' D8 format using fr-FR culture: 00001679 -00003045
' D8 format using es-ES culture: 00001679 -00003045
'
' E2 format using en-US culture: 1.68E+003 -3.05E+003
' E2 format using fr-FR culture: 1,68E+003 -3,05E+003
' E2 format using es-ES culture: 1,68E+003 -3,05E+003
'
' F format using en-US culture: 1679.00 -3045.00
' F format using fr-FR culture: 1679,00 -3045,00
' F format using es-ES culture: 1679,00 -3045,00
'
' N format using en-US culture: 1,679.00 -3,045.00
' N format using fr-FR culture: 1 679,00 -3 045,00
' N format using es-ES culture: 1.679,00 -3.045,00
'
' P format using en-US culture: 167,900.00 % -304,500.00 %
' P format using fr-FR culture: 167 900,00 % -304 500,00 %
' P format using es-ES culture: 167.900,00 % -304.500,00 %
'
' X8 format using en-US culture: 0000068F FFFFF41B
' X8 format using fr-FR culture: 0000068F FFFFF41B
' X8 format using es-ES culture: 0000068F FFFFF41B
注釈
メソッドは、指定された ToString(String, IFormatProvider) Int32 カルチャのオブジェクトを使用して、指定された書式で値の書式を設定し NumberFormatInfo ます。The ToString(String, IFormatProvider) method formats an Int32 value in a specified format by using the NumberFormatInfo object of a specified culture. 既定の書式設定またはカルチャ設定を使用する場合は、次のようにメソッドの他のオーバーロードを使用し ToString ます。If you want to use default format or culture settings, use the other overloads of the ToString method, as follows:
形式を使用するにはTo use format | カルチャの場合For culture | オーバーロードを使用するUse the overload |
---|---|---|
既定 ("G") 形式Default ("G") format | 既定の (現在の) カルチャDefault (current) culture | ToString() |
既定 ("G") 形式Default ("G") format | 特定のカルチャA specific culture | ToString(IFormatProvider) |
特定の形式A specific format | 既定の (現在の) カルチャDefault (current) culture | ToString(String) |
パラメーターには、 format
標準またはカスタムの数値書式指定文字列を指定できます。The format
parameter can be either a standard or a custom numeric format string. すべてのカスタム数値書式指定文字と同様に、"R" (または "r") 以外のすべての標準の数値書式指定文字列がサポートされます。All standard numeric format strings other than "R" (or "r") are supported, as are all custom numeric format characters. format
が null
または空の文字列 ("") の場合、このインスタンスの戻り値は、一般的な数値書式指定子 ("G") で書式設定されます。If format
is null
or an empty string (""), the return value for this instance is formatted with the general numeric format specifier ("G").
パラメーターは、 provider
インターフェイスを実装するオブジェクトです IFormatProvider 。The provider
parameter is an object that implements the IFormatProvider interface. このメソッドは、 GetFormat NumberFormatInfo このメソッドによって返される文字列の書式に関するカルチャ固有の書式情報を提供するオブジェクトを返します。Its GetFormat method returns a NumberFormatInfo object that provides culture-specific format information about the format of the string that is returned by this method. を実装するオブジェクトは IFormatProvider 、次のいずれかになります。The object that implements IFormatProvider can be any of the following:
CultureInfo書式設定規則を使用するカルチャを表すオブジェクト。A CultureInfo object that represents the culture whose formatting rules are to be used.
NumberFormatInfoこの値の特定の数値書式情報を格納しているオブジェクト。A NumberFormatInfo object that contains specific numeric formatting information for this value.
IFormatProviderを実装し、 GetFormat NumberFormatInfo 書式設定情報を提供するオブジェクトを返すメソッドを持つカスタムオブジェクト。A custom object that implements IFormatProvider and whose GetFormat method returns a NumberFormatInfo object that provides formatting information.
がである provider
null
か、 NumberFormatInfo からオブジェクトを取得できない場合 provider
、このインスタンスの戻り値は、現在のカルチャので書式設定され NumberFormatInfo ます。If provider
is null
or a NumberFormatInfo object cannot be obtained from provider
, the return value for this instance is formatted with the NumberFormatInfo for the current culture.
.NET ではさまざまな書式設定がサポートされています。詳細については、次の書式設定に関するトピックを参照してください。.NET provides extensive formatting support, which is described in greater detail in the following formatting topics:
数値書式指定子の詳細については、「 標準の数値書式指定文字列 」および「 カスタム数値書式指定文字列」を参照してください。For more information about numeric format specifiers, see Standard Numeric Format Strings and Custom Numeric Format Strings.
書式設定の詳細については、「 型の書式設定」を参照してください。For more information about formatting, see Formatting Types.
こちらもご覧ください
- Parse(String)
- .NET での型の書式設定Formatting Types in .NET
- 標準の数値書式指定文字列Standard Numeric Format Strings
- カスタム数値形式文字列Custom Numeric Format Strings
- 方法: 数値に先行するゼロを埋め込むHow to: Pad a Number with Leading Zeros
- サンプル: .NET Core WinForms 書式設定ユーティリティ (C#)Sample: .NET Core WinForms Formatting Utility (C#)
- サンプル: .NET Core WinForms 書式設定ユーティリティ (Visual Basic)Sample: .NET Core WinForms Formatting Utility (Visual Basic)
適用対象
ToString(String)
指定した書式を使用して、このインスタンスの数値を、それと等価な文字列形式に変換します。Converts the numeric value of this instance to its equivalent string representation, using the specified format.
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
標準またはカスタムの数値書式指定文字列。A standard or custom numeric format string.
戻り値
format
で指定された、このインスタンスの値の文字列形式。The string representation of the value of this instance as specified by format
.
例外
format
は使用できないか、またはサポートされていません。format
is invalid or not supported.
例
次の例では、 Int32 サポートされている各標準数値書式指定子と、2つのカスタム数値書式指定文字列を使用して値を表示します。The following example displays an Int32 value using each of the supported standard numeric format specifiers, together with two custom numeric format strings. 数値を文字列に変換する場合、この例では en-us カルチャの書式指定規則を使用します。In converting the numeric values to strings, the example uses the formatting conventions of the en-US culture.
using namespace System;
void main()
{
int value = -16325;
String^ specifier;
// Use standard numeric format specifiers.
specifier = "G";
Console::WriteLine("{0}: {1}", specifier, value.ToString(specifier));
specifier = "C";
Console::WriteLine("{0}: {1}", specifier, value.ToString(specifier));
specifier = "D8";
Console::WriteLine("{0}: {1}", specifier, value.ToString(specifier));
specifier = "E4";
Console::WriteLine("{0}: {1}", specifier, value.ToString(specifier));
specifier = "e3";
Console::WriteLine("{0}: {1}", specifier, value.ToString(specifier));
specifier = "F";
Console::WriteLine("{0}: {1}", specifier, value.ToString(specifier));
specifier = "N";
Console::WriteLine("{0}: {1}", specifier, value.ToString(specifier));
specifier = "P";
Console::WriteLine("{0}: {1}", specifier, (value/100000).ToString(specifier));
specifier = "X";
Console::WriteLine("{0}: {1}", specifier, value.ToString(specifier));
// Use custom numeric format specifiers.
specifier = "0,0.000";
Console::WriteLine("{0}: {1}", specifier, value.ToString(specifier));
specifier = "#,#.00#;(#,#.00#)";
Console::WriteLine("{0}: {1}", specifier, (value*-1).ToString(specifier));
}
// The example displays the following output:
// G: -16325
// C: ($16,325.00)
// D8: -00016325
// E4: -1.6325E+004
// e3: -1.633e+004
// F: -16325.00
// N: -16,325.00
// P: 0.00 %
// X: FFFFC03B
// 0,0.000: -16,325.000
// #,#.00#;(#,#.00#): 16,325.00
int value = -16325;
string specifier;
// Use standard numeric format specifier.
specifier = "G";
Console.WriteLine("{0}: {1}", specifier, value.ToString(specifier));
// Displays: G: -16325
specifier = "C";
Console.WriteLine("{0}: {1}", specifier, value.ToString(specifier));
// Displays: C: ($16,325.00)
specifier = "D8";
Console.WriteLine("{0}: {1}", specifier, value.ToString(specifier));
// Displays: D8: -00016325
specifier = "E4";
Console.WriteLine("{0}: {1}", specifier, value.ToString(specifier));
// Displays: E4: -1.6325E+004
specifier = "e3";
Console.WriteLine("{0}: {1}", specifier, value.ToString(specifier));
// Displays: e3: -1.633e+004
specifier = "F";
Console.WriteLine("{0}: {1}", specifier, value.ToString(specifier));
// Displays: F: -16325.00
specifier = "N";
Console.WriteLine("{0}: {1}", specifier, value.ToString(specifier));
// Displays: N: -16,325.00
specifier = "P";
Console.WriteLine("{0}: {1}", specifier, (value/100000).ToString(specifier));
// Displays: P: -16.33 %
specifier = "X";
Console.WriteLine("{0}: {1}", specifier, value.ToString(specifier));
// Displays: X: FFFFC03B
// Use custom numeric format specifiers.
specifier = "0,0.000";
Console.WriteLine("{0}: {1}", specifier, value.ToString(specifier));
// Displays: 0,0.000: -16,325.000
specifier = "#,#.00#;(#,#.00#)";
Console.WriteLine("{0}: {1}", specifier, (value*-1).ToString(specifier));
// Displays: #,#.00#;(#,#.00#): 16,325.00
Dim value As Integer = -16325
Dim specifier As String
' Use standard numeric format specifier.
specifier = "G"
Console.WriteLine("{0}: {1}", specifier, value.ToString(specifier))
' Displays: G: -16325
specifier = "C"
Console.WriteLine("{0}: {1}", specifier, value.ToString(specifier))
' Displays: C: ($16,325.00)
specifier = "D8"
Console.WriteLine("{0}: {1}", specifier, value.ToString(specifier))
' Displays: D8: -00016325
specifier = "E4"
Console.WriteLine("{0}: {1}", specifier, value.ToString(specifier))
' Displays: E4: -1.6325E+004
specifier = "e3"
Console.WriteLine("{0}: {1}", specifier, value.ToString(specifier))
' Displays: e3: -1.633e+004
specifier = "F"
Console.WriteLine("{0}: {1}", specifier, value.ToString(specifier))
' Displays: F: -16325.00
specifier = "N"
Console.WriteLine("{0}: {1}", specifier, value.ToString(specifier))
' Displays: N: -16,325.00
specifier = "P"
Console.WriteLine("{0}: {1}", specifier, (value/100000).ToString(specifier))
' Displays: P: -16.33 %
specifier = "X"
Console.WriteLine("{0}: {1}", specifier, value.ToString(specifier))
' Displays: X: FFFFC03B
' Use custom numeric format specifiers.
specifier = "0,0.000"
Console.WriteLine("{0}: {1}", specifier, value.ToString(specifier))
' Displays: 0,0.000: -16,325.000
specifier = "#,#.00#;(#,#.00#)"
Console.WriteLine("{0}: {1}", specifier, (value*-1).ToString(specifier))
' Displays: #,#.00#;(#,#.00#): 16,325.00
注釈
メソッドは、 ToString(String) Int32 現在の NumberFormatInfo カルチャの規則を表すオブジェクトを使用して、指定した書式で値の書式を設定します。The ToString(String) method formats an Int32 value in a specified format by using a NumberFormatInfo object that represents the conventions of the current culture. 既定の形式 ("G" または一般) を使用する場合、または別のカルチャを指定する場合は、次のようにメソッドの他のオーバーロードを使用し ToString ます。If you want to use the default ("G", or general) format or specify a different culture, use the other overloads of the ToString method, as follows:
形式を使用するにはTo use format | カルチャの場合For culture | オーバーロードを使用するUse the overload |
---|---|---|
既定 ("G") 形式Default ("G") format | 既定の (現在の) カルチャDefault (current) culture | ToString() |
既定 ("G") 形式Default ("G") format | 特定のカルチャA specific culture | ToString(IFormatProvider) |
特定の形式A specific format | 特定のカルチャA specific culture | ToString(String, IFormatProvider) |
パラメーターには、 format
"R" 以外の任意の有効な標準数値書式指定子、およびカスタム数値書式指定子の任意の組み合わせを指定できます。The format
parameter can be any valid standard numeric format specifier except for "R", as well as any combination of custom numeric format specifiers. format
が null
または空の文字列 ("") の場合、このインスタンスの戻り値は、一般的な数値書式指定子 ("G") で書式設定されます。If format
is null
or an empty string (""), the return value of this instance is formatted with the general numeric format specifier ("G").
.NET ではさまざまな書式設定がサポートされています。詳細については、次の書式設定に関するトピックを参照してください。.NET provides extensive formatting support, which is described in greater detail in the following formatting topics:
数値書式指定子の詳細については、「 標準の数値書式指定文字列 」および「 カスタム数値書式指定文字列」を参照してください。For more information about numeric format specifiers, see Standard Numeric Format Strings and Custom Numeric Format Strings.
書式設定の詳細については、「 型の書式設定」を参照してください。For more information about formatting, see Formatting Types.
このインスタンスの戻り値は、現在のカルチャので書式設定され NumberFormatInfo ます。The return value of this instance is formatted with the NumberFormatInfo for the current culture.
こちらもご覧ください
- Parse(String)
- String
- .NET での型の書式設定Formatting Types in .NET
- 標準の数値書式指定文字列Standard Numeric Format Strings
- カスタム数値形式文字列Custom Numeric Format Strings
- 方法: 数値に先行するゼロを埋め込むHow to: Pad a Number with Leading Zeros
適用対象
ToString()
このインスタンスの数値を、それと等価な文字列形式に変換します。Converts the numeric value of this instance to its equivalent string representation.
public:
override System::String ^ ToString();
public override string ToString ();
override this.ToString : unit -> string
Public Overrides Function ToString () As String
戻り値
値が負の場合はマイナス記号を伴い、先行ゼロを含まない 0 から 9 の一連の数字から構成される、このインスタンスの値の文字列形式。The string representation of the value of this instance, consisting of a negative sign if the value is negative, and a sequence of digits ranging from 0 to 9 with no leading zeroes.
例
次の例では、 Int32 既定のメソッドを使用して値を表示し ToString() ます。The following example displays an Int32 value using the default ToString() method. また、 Int32 多くの標準書式指定子を使用した結果として得られる値の文字列形式も表示されます。It also displays the string representations of the Int32 value that results from using a number of standard format specifiers. これらの例は、en-us カルチャの書式指定規則を使用して表示されます。The examples are displayed using the formatting conventions of the en-US culture.
using namespace System;
void main()
{
int value = -16325;
// Display value using default ToString method.
Console::WriteLine(value.ToString());
// Display value using some standard format specifiers.
Console::WriteLine(value.ToString("G"));
Console::WriteLine(value.ToString("C"));
Console::WriteLine(value.ToString("D"));
Console::WriteLine(value.ToString("F"));
Console::WriteLine(value.ToString("N"));
Console::WriteLine(value.ToString("X"));
}
// The example displays the following output:
// -16325
// -16325
// ($16,325.00)
// -16325
// -16325.00
// -16,325.00
// FFFFC03B
int value = -16325;
// Display value using default ToString method.
Console.WriteLine(value.ToString()); // Displays -16325
// Display value using some standard format specifiers.
Console.WriteLine(value.ToString("G")); // Displays -16325
Console.WriteLine(value.ToString("C")); // Displays ($16,325.00)
Console.WriteLine(value.ToString("D")); // Displays -16325
Console.WriteLine(value.ToString("F")); // Displays -16325.00
Console.WriteLine(value.ToString("N")); // Displays -16,325.00
Console.WriteLine(value.ToString("X")); // Displays FFFFC03B
Dim value As Integer = -16325
' Display value using default ToString method.
Console.WriteLine(value.ToString()) ' Displays -16325
' Display value using some standard format specifiers.
Console.WriteLine(value.ToString("G")) ' Displays -16325
Console.WriteLine(value.ToString("C")) ' Displays ($16,325.00)
Console.WriteLine(value.ToString("D")) ' Displays -16325
Console.WriteLine(value.ToString("F")) ' Displays -16325.00
Console.WriteLine(value.ToString("N")) ' Displays -16,325.00
Console.WriteLine(value.ToString("X")) ' Displays FFFFC03B
注釈
メソッドは、 ToString() Int32 現在のカルチャのオブジェクトを使用して、既定の ("G" または "general") 形式の値を書式設定し NumberFormatInfo ます。The ToString() method formats an Int32 value in the default ("G", or general) format by using the NumberFormatInfo object of the current culture. 別の形式またはカルチャを指定する場合は、次のようにメソッドの他のオーバーロードを使用し ToString ます。If you want to specify a different format or culture, use the other overloads of the ToString method, as follows:
形式を使用するにはTo use format | カルチャの場合For culture | オーバーロードを使用するUse the overload |
---|---|---|
既定 ("G") 形式Default ("G") format | 特定のカルチャA specific culture | ToString(IFormatProvider) |
特定の形式A specific format | 既定の (現在の) カルチャDefault (current) culture | ToString(String) |
特定の形式A specific format | 特定のカルチャA specific culture | ToString(String, IFormatProvider) |
.NET ではさまざまな書式設定がサポートされています。詳細については、次の書式設定に関するトピックを参照してください。.NET provides extensive formatting support, which is described in greater detail in the following formatting topics:
数値書式指定子の詳細については、「 標準の数値書式指定文字列 」および「 カスタム数値書式指定文字列」を参照してください。For more information about numeric format specifiers, see Standard Numeric Format Strings and Custom Numeric Format Strings.
書式設定の詳細については、「 型の書式設定」を参照してください。For more information about formatting, see Formatting Types.