Decimal.TryParse 메서드

정의

숫자의 문자열 표현을 해당하는 Decimal로 변환합니다. 반환 값은 변환이 성공했는지 아니면 실패했는지를 나타냅니다.

오버로드

TryParse(ReadOnlySpan<Byte>, Decimal)

숫자의 문자열 표현을 포함하는 UTF-8 문자 범위를 부호 있는 10진수로 변환하려고 시도합니다.

TryParse(ReadOnlySpan<Char>, Decimal)

지정된 스타일 및 문화권별 지정 형식을 사용하여 숫자의 범위 표현을 해당하는 Decimal로 변환합니다. 반환 값은 변환이 성공했는지 아니면 실패했는지를 나타냅니다.

TryParse(String, Decimal)

숫자의 문자열 표현을 해당하는 Decimal로 변환합니다. 반환 값은 변환이 성공했는지 아니면 실패했는지를 나타냅니다.

TryParse(ReadOnlySpan<Byte>, IFormatProvider, Decimal)

UTF-8 문자 범위를 값으로 구문 분석하려고 시도합니다.

TryParse(ReadOnlySpan<Char>, IFormatProvider, Decimal)

문자 범위를 값으로 구문 분석하려고 합니다.

TryParse(String, IFormatProvider, Decimal)

문자열을 값으로 구문 분석하려고 합니다.

TryParse(ReadOnlySpan<Byte>, NumberStyles, IFormatProvider, Decimal)

UTF-8 문자 범위를 값으로 구문 분석하려고 시도합니다.

TryParse(ReadOnlySpan<Char>, NumberStyles, IFormatProvider, Decimal)

지정된 스타일 및 문화권별 지정 형식을 사용하여 숫자의 범위 표현을 해당하는 Decimal로 변환합니다. 반환 값은 변환이 성공했는지 아니면 실패했는지를 나타냅니다.

TryParse(String, NumberStyles, IFormatProvider, Decimal)

지정된 스타일 및 문화권별 형식을 사용하여 숫자의 문자열 표현을 해당하는 Decimal로 변환합니다. 반환 값은 변환이 성공했는지 아니면 실패했는지를 나타냅니다.

TryParse(ReadOnlySpan<Byte>, Decimal)

Source:
Decimal.cs
Source:
Decimal.cs

숫자의 문자열 표현을 포함하는 UTF-8 문자 범위를 부호 있는 10진수로 변환하려고 시도합니다.

public:
 static bool TryParse(ReadOnlySpan<System::Byte> utf8Text, [Runtime::InteropServices::Out] System::Decimal % result);
public static bool TryParse (ReadOnlySpan<byte> utf8Text, out decimal result);
static member TryParse : ReadOnlySpan<byte> * decimal -> bool
Public Shared Function TryParse (utf8Text As ReadOnlySpan(Of Byte), ByRef result As Decimal) As Boolean

매개 변수

utf8Text
ReadOnlySpan<Byte>

변환할 숫자를 나타내는 UTF-8 문자를 포함하는 범위입니다.

result
Decimal

이 메서드가 반환될 때 변환에 성공한 경우 에 포함된 수에 utf8Text 해당하는 부호 있는 10진수 값을 포함하거나 변환에 실패한 경우 0을 포함합니다. 이 매개 변수는 초기화되지 않은 상태로 전달됩니다. 원래 결과에 제공된 모든 값을 덮어쓰게 됩니다.

반환

utf8Text이(가) 성공적으로 변환되었으면 true이고, 그렇지 않으면 false입니다.

적용 대상

TryParse(ReadOnlySpan<Char>, Decimal)

Source:
Decimal.cs
Source:
Decimal.cs
Source:
Decimal.cs

지정된 스타일 및 문화권별 지정 형식을 사용하여 숫자의 범위 표현을 해당하는 Decimal로 변환합니다. 반환 값은 변환이 성공했는지 아니면 실패했는지를 나타냅니다.

public:
 static bool TryParse(ReadOnlySpan<char> s, [Runtime::InteropServices::Out] System::Decimal % result);
public static bool TryParse (ReadOnlySpan<char> s, out decimal result);
static member TryParse : ReadOnlySpan<char> * decimal -> bool
Public Shared Function TryParse (s As ReadOnlySpan(Of Char), ByRef result As Decimal) As Boolean

매개 변수

s
ReadOnlySpan<Char>

변환할 숫자를 나타내는 문자를 포함하는 범위입니다.

result
Decimal

이 메서드가 반환될 때 변환이 성공한 경우 s에 포함된 숫자에 해당하는 Decimal 숫자가 들어 있고, 변환이 실패한 경우 0이 들어 있습니다. 매개 변수가 또는 Emptynull 이거나 와 호환style되는 형식의 숫자가 아니거나 Decimal.MinValue보다 작거나 Decimal.MaxValue보다 큰 숫자를 나타내는 경우 s 변환이 실패합니다. 이 매개 변수는 초기화되지 않은 상태로 전달됩니다. 원래 result에 제공된 모든 값을 덮어씁니다.

반환

s이(가) 성공적으로 변환되었으면 true이고, 그렇지 않으면 false입니다.

적용 대상

TryParse(String, Decimal)

Source:
Decimal.cs
Source:
Decimal.cs
Source:
Decimal.cs

숫자의 문자열 표현을 해당하는 Decimal로 변환합니다. 반환 값은 변환이 성공했는지 아니면 실패했는지를 나타냅니다.

public:
 static bool TryParse(System::String ^ s, [Runtime::InteropServices::Out] System::Decimal % result);
public static bool TryParse (string s, out decimal result);
public static bool TryParse (string? s, out decimal result);
static member TryParse : string * decimal -> bool
Public Shared Function TryParse (s As String, ByRef result As Decimal) As Boolean

매개 변수

s
String

변환할 숫자의 문자열 표현입니다.

result
Decimal

이 메서드가 반환될 때 변환이 성공한 경우 s에 포함된 숫자에 해당하는 Decimal 숫자가 들어 있고, 변환이 실패한 경우 0이 들어 있습니다. 매개 변수가 또는 이 null 유효한 Empty형식의 숫자가 아니거나 Decimal.MinValue보다 작거나 Decimal.MaxValue보다 큰 숫자를 나타내는 경우 s 변환이 실패합니다. 이 매개 변수는 초기화되지 않은 상태로 전달됩니다. 원래 result에 제공된 모든 값을 덮어씁니다.

반환

s이(가) 성공적으로 변환되었으면 true이고, 그렇지 않으면 false입니다.

예제

다음 예제에서는 메서드를 Decimal.TryParse(String, Decimal) 사용하여 숫자 값의 문자열 표현을 값으로 Decimal 변환합니다. en-US가 현재 문화권이라고 가정합니다.

string value;
decimal number;

// Parse a floating-point value with a thousands separator.
value = "1,643.57";
if (Decimal.TryParse(value, out number))
   Console.WriteLine(number);
else
   Console.WriteLine("Unable to parse '{0}'.", value);

// Parse a floating-point value with a currency symbol and a
// thousands separator.
value = "$1,643.57";
if (Decimal.TryParse(value, out number))
   Console.WriteLine(number);
else
   Console.WriteLine("Unable to parse '{0}'.", value);

// Parse value in exponential notation.
value = "-1.643e6";
if (Decimal.TryParse(value, out number))
   Console.WriteLine(number);
else
   Console.WriteLine("Unable to parse '{0}'.", value);

// Parse a negative integer value.
value = "-1689346178821";
if (Decimal.TryParse(value, out number))
   Console.WriteLine(number);
else
   Console.WriteLine("Unable to parse '{0}'.", value);
// The example displays the following output to the console:
//       1643.57
//       Unable to parse '$1,643.57'.
//       Unable to parse '-1.643e6'.
//       -1689346178821
// Parse a floating-point value with a thousands separator.
let value = "1,643.57"
match Decimal.TryParse value with
| true, number ->
    printfn $"{number}"
| _ ->
    printfn $"Unable to parse '{value}'."

// Parse a floating-point value with a currency symbol and a
// thousands separator.
let value = "$1,643.57"
match Decimal.TryParse value with
| true, number ->
    printfn $"{number}"
| _ -> 
    printfn $"Unable to parse '{value}'."

// Parse value in exponential notation.
let value = "-1.643e6"
match Decimal.TryParse value with
| true, number ->
    printfn $"{number}"
| _ -> 
    printfn $"Unable to parse '{value}'."

// Parse a negative integer value.
let value = "-1689346178821"
match Decimal.TryParse value with
| true, number ->
    printfn $"{number}"
| _ -> 
    printfn $"Unable to parse '{value}'."
// The example displays the following output to the console:
//       1643.57
//       Unable to parse '$1,643.57'.
//       Unable to parse '-1.643e6'.
//       -1689346178821
Dim value As String
Dim number As Decimal

' Parse a floating-point value with a thousands separator.
value = "1,643.57"
If Decimal.TryParse(value, number) Then
   Console.WriteLine(number)
Else
   Console.WriteLine("Unable to parse '{0}'.", value)      
End If   

' Parse a floating-point value with a currency symbol and a 
' thousands separator.
value = "$1,643.57"
If Decimal.TryParse(value, number) Then
   Console.WriteLine(number)  
Else
   Console.WriteLine("Unable to parse '{0}'.", value)   
End If

' Parse value in exponential notation.
value = "-1.643e6"
If Decimal.TryParse(value, number)
   Console.WriteLine(number)
Else
   Console.WriteLine("Unable to parse '{0}'.", value)   
End If

' Parse a negative integer value.
value = "-1689346178821"
If Decimal.TryParse(value, number)
   Console.WriteLine(number)
Else
   Console.WriteLine("Unable to parse '{0}'.", value)   
End If
' The example displays the following output to the console:
'       1643.57
'       Unable to parse '$1,643.57'.
'       Unable to parse '-1.643e6'.
'       -1689346178821

설명

이 오버로드는 구문 분석된 숫자 값을 반환하는 대신 구문 분석 작업이 성공했는지 여부를 나타내는 부울 값을 반환하여 메서드와 다릅니다 Decimal.Parse(String) . 예외 처리를 사용하여 유효하지 않고 성공적으로 구문 분석할 수 없는 경우 s 를 테스트 FormatException 할 필요가 없습니다.

매개 변수 s 에는 다음과 같은 다양한 형식이 포함됩니다.

[ws] [기호] [digits,]digits[.fractional-digits][ws]

대괄호 ([ 및 ]) 안의 요소는 선택적 요소입니다. 다음 표에서는 각 요소에 대해 설명합니다.

요소 설명
ws 선택적 공백입니다.
sign 선택적 기호입니다.
숫자 0에서 9 사이의 숫자 시퀀스입니다.
, 문화권별 천 단위 구분 기호입니다.
. 문화권별 소수점 기호입니다.
fractional-digits 0에서 9 사이의 숫자 시퀀스입니다.

매개 변수 s 는 스타일을 사용하여 해석됩니다 NumberStyles.Number . 즉, 공백과 수천 개의 구분 기호가 허용되지만 통화 기호는 허용되지 않습니다. 에 있을 s수 있는 요소(예: 통화 기호, 천 단위 구분 기호 및 공백)를 명시적으로 정의하려면 메서드 오버로드를 Decimal.TryParse(String, NumberStyles, IFormatProvider, Decimal) 사용합니다.

매개 변수 s 는 현재 시스템 문화권에 대해 초기화된 개체의 NumberFormatInfo 서식 정보를 사용하여 구문 분석됩니다. 자세한 내용은 CurrentInfo를 참조하세요. 다른 지정된 문화권의 서식 정보를 사용하여 문자열을 구문 분석하려면 메서드 오버로드를 Decimal.TryParse(String, NumberStyles, IFormatProvider, Decimal) 사용합니다.

필요한 경우 의 값 s 은 반올림을 사용하여 가장 가까운 값으로 반올림됩니다.

개체의 Decimal 전체 자릿수는 29자리입니다. 29자리를 초과하지만 소수 부분이 있고 및 MinValue범위 MaxValue 내에 있는 숫자를 나타내는 경우 s 반올림을 사용하여 가장 가까운 숫자로 반올림되고 잘리지 않고 29자리로 반올림됩니다.

구문 분석 작업 중에 매개 변수에서 s 구분 기호가 발견되고 해당 통화 또는 숫자 10진수 및 그룹 구분 기호가 동일한 경우 구문 분석 작업은 구분 기호가 그룹 구분 기호가 아닌 소수 구분 기호라고 가정합니다. 구분 기호에 대한 자세한 내용은 , , NumberDecimalSeparatorCurrencyGroupSeparatorNumberGroupSeparator를 참조CurrencyDecimalSeparator하세요.

추가 정보

적용 대상

TryParse(ReadOnlySpan<Byte>, IFormatProvider, Decimal)

Source:
Decimal.cs
Source:
Decimal.cs

UTF-8 문자 범위를 값으로 구문 분석하려고 시도합니다.

public:
 static bool TryParse(ReadOnlySpan<System::Byte> utf8Text, IFormatProvider ^ provider, [Runtime::InteropServices::Out] System::Decimal % result) = IUtf8SpanParsable<System::Decimal>::TryParse;
public static bool TryParse (ReadOnlySpan<byte> utf8Text, IFormatProvider? provider, out decimal result);
static member TryParse : ReadOnlySpan<byte> * IFormatProvider * decimal -> bool
Public Shared Function TryParse (utf8Text As ReadOnlySpan(Of Byte), provider As IFormatProvider, ByRef result As Decimal) As Boolean

매개 변수

utf8Text
ReadOnlySpan<Byte>

구문 분석할 UTF-8자의 범위입니다.

provider
IFormatProvider

utf8Text에 대한 문화권별 서식 정보를 제공하는 개체입니다.

result
Decimal

반환 시 에는 성공적으로 구문 분석 utf8Text 한 결과 또는 실패 시 정의되지 않은 값이 포함됩니다.

반환

true 가 성공적으로 구문 분석되었으면 utf8Text 이고, false그렇지 않으면 입니다.

적용 대상

TryParse(ReadOnlySpan<Char>, IFormatProvider, Decimal)

Source:
Decimal.cs
Source:
Decimal.cs
Source:
Decimal.cs

문자 범위를 값으로 구문 분석하려고 합니다.

public:
 static bool TryParse(ReadOnlySpan<char> s, IFormatProvider ^ provider, [Runtime::InteropServices::Out] System::Decimal % result) = ISpanParsable<System::Decimal>::TryParse;
public static bool TryParse (ReadOnlySpan<char> s, IFormatProvider? provider, out decimal result);
static member TryParse : ReadOnlySpan<char> * IFormatProvider * decimal -> bool
Public Shared Function TryParse (s As ReadOnlySpan(Of Char), provider As IFormatProvider, ByRef result As Decimal) As Boolean

매개 변수

s
ReadOnlySpan<Char>

구문 분석할 문자의 범위입니다.

provider
IFormatProvider

s에 대한 문화권별 서식 정보를 제공하는 개체입니다.

result
Decimal

이 메서드가 반환될 때 에는 성공적으로 구문 분석 s한 결과 또는 실패 시 정의되지 않은 값이 포함됩니다.

반환

true 가 성공적으로 구문 분석되었으면 s 이고, false그렇지 않으면 입니다.

적용 대상

TryParse(String, IFormatProvider, Decimal)

Source:
Decimal.cs
Source:
Decimal.cs
Source:
Decimal.cs

문자열을 값으로 구문 분석하려고 합니다.

public:
 static bool TryParse(System::String ^ s, IFormatProvider ^ provider, [Runtime::InteropServices::Out] System::Decimal % result) = IParsable<System::Decimal>::TryParse;
public static bool TryParse (string? s, IFormatProvider? provider, out decimal result);
static member TryParse : string * IFormatProvider * decimal -> bool
Public Shared Function TryParse (s As String, provider As IFormatProvider, ByRef result As Decimal) As Boolean

매개 변수

s
String

구문 분석할 문자열입니다.

provider
IFormatProvider

s에 대한 문화권별 서식 정보를 제공하는 개체입니다.

result
Decimal

이 메서드가 반환될 때 실패 시 성공적으로 구문 분석 s 한 결과 또는 정의되지 않은 값이 포함됩니다.

반환

true 가 성공적으로 구문 분석되었으면 s 이고, false그렇지 않으면 입니다.

적용 대상

TryParse(ReadOnlySpan<Byte>, NumberStyles, IFormatProvider, Decimal)

Source:
Decimal.cs
Source:
Decimal.cs

UTF-8 문자 범위를 값으로 구문 분석하려고 시도합니다.

public:
 static bool TryParse(ReadOnlySpan<System::Byte> utf8Text, System::Globalization::NumberStyles style, IFormatProvider ^ provider, [Runtime::InteropServices::Out] System::Decimal % result) = System::Numerics::INumberBase<System::Decimal>::TryParse;
public static bool TryParse (ReadOnlySpan<byte> utf8Text, System.Globalization.NumberStyles style, IFormatProvider? provider, out decimal result);
static member TryParse : ReadOnlySpan<byte> * System.Globalization.NumberStyles * IFormatProvider * decimal -> bool
Public Shared Function TryParse (utf8Text As ReadOnlySpan(Of Byte), style As NumberStyles, provider As IFormatProvider, ByRef result As Decimal) As Boolean

매개 변수

utf8Text
ReadOnlySpan<Byte>

구문 분석할 UTF-8자의 범위입니다.

style
NumberStyles

utf8Text있을 수 있는 숫자 스타일의 비트 조합입니다.

provider
IFormatProvider

utf8Text에 대한 문화권별 서식 정보를 제공하는 개체입니다.

result
Decimal

반환 시 에는 성공적으로 구문 분석 utf8Text 한 결과 또는 실패 시 정의되지 않은 값이 포함됩니다.

반환

true 가 성공적으로 구문 분석되었으면 utf8Text 이고, false그렇지 않으면 입니다.

적용 대상

TryParse(ReadOnlySpan<Char>, NumberStyles, IFormatProvider, Decimal)

Source:
Decimal.cs
Source:
Decimal.cs
Source:
Decimal.cs

지정된 스타일 및 문화권별 지정 형식을 사용하여 숫자의 범위 표현을 해당하는 Decimal로 변환합니다. 반환 값은 변환이 성공했는지 아니면 실패했는지를 나타냅니다.

public:
 static bool TryParse(ReadOnlySpan<char> s, System::Globalization::NumberStyles style, IFormatProvider ^ provider, [Runtime::InteropServices::Out] System::Decimal % result);
public:
 static bool TryParse(ReadOnlySpan<char> s, System::Globalization::NumberStyles style, IFormatProvider ^ provider, [Runtime::InteropServices::Out] System::Decimal % result) = System::Numerics::INumberBase<System::Decimal>::TryParse;
public static bool TryParse (ReadOnlySpan<char> s, System.Globalization.NumberStyles style, IFormatProvider? provider, out decimal result);
public static bool TryParse (ReadOnlySpan<char> s, System.Globalization.NumberStyles style, IFormatProvider provider, out decimal result);
static member TryParse : ReadOnlySpan<char> * System.Globalization.NumberStyles * IFormatProvider * decimal -> bool
Public Shared Function TryParse (s As ReadOnlySpan(Of Char), style As NumberStyles, provider As IFormatProvider, ByRef result As Decimal) As Boolean

매개 변수

s
ReadOnlySpan<Char>

변환할 숫자를 나타내는 문자를 포함하는 범위입니다.

style
NumberStyles

s에 사용할 수 있는 형식을 나타내는 열거형 값의 비트 조합입니다. 지정할 일반적인 값은 Number입니다.

provider
IFormatProvider

s에 대한 문화권별 구문 분석 정보를 제공하는 개체입니다.

result
Decimal

이 메서드가 반환될 때 변환이 성공한 경우 s에 포함된 숫자에 해당하는 Decimal 숫자가 들어 있고, 변환이 실패한 경우 0이 들어 있습니다. 매개 변수가 또는 Emptynull 이거나 와 호환style되는 형식의 숫자가 아니거나 Decimal.MinValue보다 작거나 Decimal.MaxValue보다 큰 숫자를 나타내는 경우 s 변환이 실패합니다. 이 매개 변수는 초기화되지 않은 상태로 전달됩니다. 원래 result에 제공된 모든 값을 덮어씁니다.

반환

s이(가) 성공적으로 변환되었으면 true이고, 그렇지 않으면 false입니다.

적용 대상

TryParse(String, NumberStyles, IFormatProvider, Decimal)

Source:
Decimal.cs
Source:
Decimal.cs
Source:
Decimal.cs

지정된 스타일 및 문화권별 형식을 사용하여 숫자의 문자열 표현을 해당하는 Decimal로 변환합니다. 반환 값은 변환이 성공했는지 아니면 실패했는지를 나타냅니다.

public:
 static bool TryParse(System::String ^ s, System::Globalization::NumberStyles style, IFormatProvider ^ provider, [Runtime::InteropServices::Out] System::Decimal % result);
public:
 static bool TryParse(System::String ^ s, System::Globalization::NumberStyles style, IFormatProvider ^ provider, [Runtime::InteropServices::Out] System::Decimal % result) = System::Numerics::INumberBase<System::Decimal>::TryParse;
public static bool TryParse (string s, System.Globalization.NumberStyles style, IFormatProvider provider, out decimal result);
public static bool TryParse (string? s, System.Globalization.NumberStyles style, IFormatProvider? provider, out decimal result);
static member TryParse : string * System.Globalization.NumberStyles * IFormatProvider * decimal -> bool
Public Shared Function TryParse (s As String, style As NumberStyles, provider As IFormatProvider, ByRef result As Decimal) As Boolean

매개 변수

s
String

변환할 숫자의 문자열 표현입니다.

style
NumberStyles

s에 사용할 수 있는 형식을 나타내는 열거형 값의 비트 조합입니다. 지정할 일반적인 값은 Number입니다.

provider
IFormatProvider

s에 대한 문화권별 구문 분석 정보를 제공하는 개체입니다.

result
Decimal

이 메서드가 반환될 때 변환이 성공한 경우 s에 포함된 숫자에 해당하는 Decimal 숫자가 들어 있고, 변환이 실패한 경우 0이 들어 있습니다. 매개 변수가 또는 Emptynull 이거나 와 호환style되는 형식의 숫자가 아니거나 Decimal.MinValue보다 작거나 Decimal.MaxValue보다 큰 숫자를 나타내는 경우 s 변환이 실패합니다. 이 매개 변수는 초기화되지 않은 상태로 전달됩니다. 원래 result에 제공된 모든 값을 덮어씁니다.

반환

s이(가) 성공적으로 변환되었으면 true이고, 그렇지 않으면 false입니다.

예외

styleNumberStyles 값이 아닙니다.

또는

styleAllowHexSpecifier 값입니다.

예제

다음 예제에서는 메서드를 사용하여 TryParse(String, NumberStyles, IFormatProvider, Decimal) 특정 스타일이 있고 특정 문화권의 규칙을 사용하여 서식이 지정된 숫자의 문자열 표현을 구문 분석하는 방법을 보여 줍니다.

string value;
NumberStyles style;
CultureInfo culture;
decimal number;

// Parse currency value using en-GB culture.
value = "£1,097.63";
style = NumberStyles.Number | NumberStyles.AllowCurrencySymbol;
culture = CultureInfo.CreateSpecificCulture("en-GB");
if (Decimal.TryParse(value, style, culture, out number))
   Console.WriteLine("Converted '{0}' to {1}.", value, number);
else
   Console.WriteLine("Unable to convert '{0}'.", value);
// Displays:
//       Converted '£1,097.63' to 1097.63.

value = "1345,978";
style = NumberStyles.AllowDecimalPoint;
culture = CultureInfo.CreateSpecificCulture("fr-FR");
if (Decimal.TryParse(value, style, culture, out number))
   Console.WriteLine("Converted '{0}' to {1}.", value, number);
else
   Console.WriteLine("Unable to convert '{0}'.", value);
// Displays:
//       Converted '1345,978' to 1345.978.

value = "1.345,978";
style = NumberStyles.AllowDecimalPoint | NumberStyles.AllowThousands;
culture = CultureInfo.CreateSpecificCulture("es-ES");
if (Decimal.TryParse(value, style, culture, out number))
   Console.WriteLine("Converted '{0}' to {1}.", value, number);
else
   Console.WriteLine("Unable to convert '{0}'.", value);
// Displays:
//       Converted '1.345,978' to 1345.978.

value = "1 345,978";
if (Decimal.TryParse(value, style, culture, out number))
   Console.WriteLine("Converted '{0}' to {1}.", value, number);
else
   Console.WriteLine("Unable to convert '{0}'.", value);
// Displays:
//       Unable to convert '1 345,978'.
// Parse currency value using en-GB culture.
let value = "£1,097.63"
let style = NumberStyles.Number ||| NumberStyles.AllowCurrencySymbol
let culture = CultureInfo.CreateSpecificCulture "en-GB"
match Decimal.TryParse(value, style, culture) with
| true, number ->
    printfn $"Converted '{value}' to {number}."
| _ -> 
    printfn $"Unable to convert '{value}'."
// Displays:
//       Converted '£1,097.63' to 1097.63.

let value = "1345,978"
let style = NumberStyles.AllowDecimalPoint
let culture = CultureInfo.CreateSpecificCulture "fr-FR"
match Decimal.TryParse(value, style, culture) with
| true, number ->
    printfn $"Converted '{value}' to {number}."
| _ -> 
    printfn $"Unable to convert '{value}'."
// Displays:
//       Converted '1345,978' to 1345.978.

let value = "1.345,978"
let style = NumberStyles.AllowDecimalPoint ||| NumberStyles.AllowThousands
let culture = CultureInfo.CreateSpecificCulture "es-ES"
match Decimal.TryParse(value, style, culture) with
| true, number ->
    printfn $"Converted '{value}' to {number}."
| _ -> 
    printfn $"Unable to convert '{value}'."
// Displays:
//       Converted '1.345,978' to 1345.978.

let value = "1 345,978"
match Decimal.TryParse(value, style, culture) with
| true, number ->
    printfn $"Converted '{value}' to {number}."
| _ -> 
    printfn $"Unable to convert '{value}'."
// Displays:
//       Unable to convert '1 345,978'.
Dim value As String
Dim style As NumberStyles
Dim culture As CultureInfo
Dim number As Decimal

' Parse currency value using en-GB culture.
value = "£1,097.63"
style = NumberStyles.Number Or NumberStyles.AllowCurrencySymbol
culture = CultureInfo.CreateSpecificCulture("en-GB")
If Decimal.TryParse(value, style, culture, number) Then
   Console.WriteLine("Converted '{0}' to {1}.", value, number)
Else
   Console.WriteLine("Unable to convert '{0}'.", value)
End If    
' Displays: 
'       Converted '£1,097.63' to 1097.63.

value = "1345,978"
style = NumberStyles.AllowDecimalPoint
culture = CultureInfo.CreateSpecificCulture("fr-FR")
If Decimal.TryParse(value, style, culture, number) Then
   Console.WriteLine("Converted '{0}' to {1}.", value, number)
Else
   Console.WriteLine("Unable to convert '{0}'.", value)
End If    
' Displays:
'       Converted '1345,978' to 1345.978.

value = "1.345,978"
style = NumberStyles.AllowDecimalPoint Or NumberStyles.AllowThousands
culture = CultureInfo.CreateSpecificCulture("es-ES")
If Decimal.TryParse(value, style, culture, number) Then
   Console.WriteLine("Converted '{0}' to {1}.", value, number)
Else
   Console.WriteLine("Unable to convert '{0}'.", value)
End If    
' Displays: 
'       Converted '1.345,978' to 1345.978.

value = "1 345,978"
If Decimal.TryParse(value, style, culture, number) Then
   Console.WriteLine("Converted '{0}' to {1}.", value, number)
Else
   Console.WriteLine("Unable to convert '{0}'.", value)
End If    
' Displays:
'       Unable to convert '1 345,978'.

설명

이 오버로드는 구문 분석된 숫자 값을 반환하는 대신 구문 분석 작업이 성공했는지 여부를 나타내는 부울 값을 반환하여 메서드와 다릅니다 Decimal.Parse(String, NumberStyles, IFormatProvider) . 예외 처리를 사용하여 유효하지 않고 성공적으로 구문 분석할 수 없는 경우 s 를 테스트 FormatException 할 필요가 없습니다.

매개 변수는 style 구문 분석 작업이 성공하기 위해 매개 변수의 s 허용 가능한 형식을 정의합니다. 열거형의 비트 플래그 NumberStyles 조합이어야 합니다. 다음 NumberStyles 멤버는 지원되지 않습니다.

스타일 값에 따라 매개 변수에는 s 다음 요소가 포함될 수 있습니다.

[ws] [$] [기호] [digits,]digits[.fractional-digits][e[sign]digits][ws]

대괄호 ([ 및 ]) 안의 요소는 선택적 요소입니다. 다음 표에서는 각 요소에 대해 설명합니다.

요소 설명
ws 선택적 공백입니다. 플래그가 포함된 경우 style 의 시작 부분에 s 공백이 NumberStyles.AllowLeadingWhite 나타날 수 있습니다. 플래그를 포함하는 경우 styles 끝에 표시할 NumberStyles.AllowTrailingWhite 수 있습니다.
$ 문화권별 통화 기호입니다. 문자열의 위치는 매개 변수의 메서드 provider 에서 반환된 NumberFormatInfo 개체의 또는 NumberFormatInfo.CurrencyPositivePattern 속성에 IFormatProvider.GetFormat 의해 NumberFormatInfo.CurrencyNegativePattern 정의됩니다. 플래그가 포함된 경우 style 통화 기호가 NumberStyles.AllowCurrencySymbols 나타날 수 있습니다.
sign 선택적 기호입니다.
숫자 0에서 9 사이의 숫자 시퀀스입니다.
. 문화권별 소수점 기호입니다.
fractional-digits 0에서 9 사이의 숫자 시퀀스입니다.

매개 변수는 style 매개 변수의 허용된 형식을 s 지정하며 비트 OR 연산을 사용하여 결합된 하나 이상의 NumberStyles 열거형 상수일 수 있습니다. 가 null s 이면 style 은 스타일을 사용하여 NumberStyles.Number 해석됩니다.

매개 변수는 provider 또는 개체와 같은 구현입니다 IFormatProviderNumberFormatInfo.CultureInfo 매개 변수는 provider 구문 분석에 사용되는 문화권별 정보를 제공합니다. providernull이면 현재 스레드 문화권이 사용됩니다.

개체의 Decimal 전체 자릿수는 29자리입니다. 29자리를 초과하지만 소수 부분이 있고 및 MinValue범위 MaxValue 내에 있는 숫자를 나타내는 경우 s 반올림을 사용하여 가장 가까운 숫자로 반올림되고 잘리지 않고 29자리로 반올림됩니다.

구문 분석 작업 중에 매개 변수에서 s 구분 기호가 발견되고 해당 통화 또는 숫자 10진수 및 그룹 구분 기호가 동일한 경우 구문 분석 작업은 구분 기호가 그룹 구분 기호가 아닌 소수 구분 기호라고 가정합니다. 구분 기호에 대한 자세한 내용은 , , NumberDecimalSeparatorCurrencyGroupSeparatorNumberGroupSeparator를 참조CurrencyDecimalSeparator하세요.

추가 정보

적용 대상