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 문화권의 개체를 사용 하 여 기본값 ("G" 또는 일반) 형식으로 값의 서식을 NumberFormatInfo 지정 합니다.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 Framework는 다음과 같은 서식 지정 항목에 자세히 설명 되어 있는 광범위 한 서식 지정 지원을 제공 합니다.The .NET Framework 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.
예제
다음 예제에서는 세 가지 문화권에 대해 지원 되는 각 표준 숫자 서식 지정자를 사용 하 여 양수 및 음수 값을 표시 합니다.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 Framework는 다음과 같은 서식 지정 항목에 자세히 설명 되어 있는 광범위 한 서식 지정 지원을 제공 합니다.The .NET Framework 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
- 방법: 숫자 앞에 0으로 채우기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 지원 되는 각 표준 숫자 형식 지정자와 함께 두 개의 사용자 지정 숫자 서식 문자열을 사용 하 여 값을 표시 합니다.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 Framework는 다음과 같은 서식 지정 항목에 자세히 설명 되어 있는 광범위 한 서식 지정 지원을 제공 합니다.The .NET Framework 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
- 방법: 숫자 앞에 0으로 채우기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 사이의 숫자(앞에 오는 0은 사용하지 않음)들로 구성된 이 인스턴스의 값에 대한 문자열 표현입니다.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 NumberFormatInfo 현재 문화권의 개체를 사용 하 여 기본값 ("G" 또는 일반) 형식으로 값의 형식을 지정 합니다.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 Framework는 다음과 같은 서식 지정 항목에 자세히 설명 되어 있는 광범위 한 서식 지정 지원을 제공 합니다.The .NET Framework 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.