Decimal.TryParse 方法

定义

将数字的字符串表示形式转换为其 Decimal 等效形式。 返回值指示转换是成功还是失败。

重载

名称 说明
TryParse(ReadOnlySpan<Byte>, Decimal)

尝试将包含数字字符串表示形式的 UTF-8 字符范围转换为其有符号十进制等效项。

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
Source:
Decimal.cs
Source:
Decimal.cs

尝试将包含数字字符串表示形式的 UTF-8 字符范围转换为其有符号十进制等效项。

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 数字等效的带符号十进制值;如果转换失败,则包含零。 此参数未初始化传递;将覆盖最初在结果中提供的任何值。

返回

true 如果 utf8Text 已成功转换,则为 :否则为 false

适用于

TryParse(ReadOnlySpan<Char>, Decimal)

Source:
Decimal.cs
Source:
Decimal.cs
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

此方法返回时,包含 Decimal 与所包含 s数值等效的数字(如果转换成功)或零(如果转换失败)。 如果s参数小于 nullEmpty 或大于 Decimal.MaxValue 的数字,则转换失败。 此参数传递为 uininitialized;最初提供 result 的任何值将被覆盖。

返回

true 如果 s 已成功转换,则为 :否则为 false

适用于

TryParse(String, Decimal)

Source:
Decimal.cs
Source:
Decimal.cs
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

此方法返回时,包含 Decimal 与所包含 s数值等效的数字(如果转换成功)或零(如果转换失败)。 如果 s 参数为 nullEmpty不是有效格式的数字,或者表示小于 Decimal.MinValue 或大于 Decimal.MaxValue 的数字,则转换失败。 此参数传递为 uininitialized;最初提供 result 的任何值将被覆盖。

返回

true 如果 s 已成功转换,则为 :否则为 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) ,方法是返回一个布尔值,该值指示分析操作是否成功,而不是返回已分析的数值。 它无需使用异常处理来测试 FormatException 无效且无法成功分析的事件 s

参数 s 包含多种窗体:

[ws][sign][digits,]digits[.fractional-digits][ws]

方括号 ([ 和 ]) 中的元素是可选的。 下表对每个元素进行了描述。

元素 Description
ws 可选空格。
签名 可选符号。
数字 一系列数字,范围从 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 位精度。 如果s表示数字的位数超过 29 位,但具有小数部分,并且位于该数字范围内MaxValueMinValue,并且该数字是舍入的,而不是截断的,则使用舍入到最接近的 29 位数字。

如果在分析操作期间,在参数中 s 遇到分隔符,并且适用的货币或数字小数和组分隔符相同,则分析操作假定分隔符是小数分隔符,而不是组分隔符。 有关分隔符的详细信息,请参阅CurrencyDecimalSeparatorNumberDecimalSeparatorCurrencyGroupSeparatorNumberGroupSeparator

另请参阅

适用于

TryParse(ReadOnlySpan<Byte>, IFormatProvider, Decimal)

Source:
Decimal.cs
Source:
Decimal.cs
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 的结果或失败时未定义的值。

返回

如果已成功分析,则为 0;否则为

适用于

TryParse(ReadOnlySpan<Char>, IFormatProvider, Decimal)

Source:
Decimal.cs
Source:
Decimal.cs
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的结果或失败时未定义的值。

返回

如果已成功分析,则为 0;否则为

适用于

TryParse(String, IFormatProvider, Decimal)

Source:
Decimal.cs
Source:
Decimal.cs
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 的结果或失败时未定义的值。

返回

如果已成功分析,则为 0;否则为

适用于

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

Source:
Decimal.cs
Source:
Decimal.cs
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 的结果或失败时未定义的值。

返回

如果已成功分析,则为 0;否则为

适用于

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

Source:
Decimal.cs
Source:
Decimal.cs
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) = System::Numerics::INumberBase<System::Decimal>::TryParse;
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, 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

此方法返回时,包含 Decimal 与所包含 s数值等效的数字(如果转换成功)或零(如果转换失败)。 如果s参数为nullEmpty不符合格式style的数字,或表示小于 Decimal.MinValue 或大于 Decimal.MaxValue 的数字,则转换失败。 此参数传递为 uininitialized;最初提供 result 的任何值将被覆盖。

返回

true 如果 s 已成功转换,则为 :否则为 false

适用于

TryParse(String, NumberStyles, IFormatProvider, Decimal)

Source:
Decimal.cs
Source:
Decimal.cs
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

此方法返回时,包含 Decimal 与所包含 s数值等效的数字(如果转换成功)或零(如果转换失败)。 如果s参数为nullEmpty不符合格式style的数字,或表示小于 Decimal.MinValue 或大于 Decimal.MaxValue 的数字,则转换失败。 此参数传递为 uininitialized;最初提供 result 的任何值将被覆盖。

返回

true 如果 s 已成功转换,则为 :否则为 false

例外

style 不是值 NumberStyles

-或-

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) ,方法是返回一个布尔值,该值指示分析操作是否成功,而不是返回已分析的数值。 它无需使用异常处理来测试 FormatException 无效且无法成功分析的事件 s

style 参数定义参数允许的格式 s ,以便分析操作成功。 它必须是枚举中的 NumberStyles 位标志的组合。 不支持以下 NumberStyles 成员:

根据样式的值,参数 s 可能包含以下元素:

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

方括号 ([ 和 ]) 中的元素是可选的。 下表对每个元素进行了描述。

元素 Description
ws 可选空格。 如果s包含style标志,则空白可以出现在开头NumberStyles.AllowLeadingWhite。 如果s包含style标志,则它可以显示在末尾NumberStyles.AllowTrailingWhite
$ 区域性特定的货币符号。 字符串中的位置由NumberFormatInfo.CurrencyNegativePattern参数方法NumberFormatInfo.CurrencyPositivePattern返回NumberFormatInfo的对象或IFormatProvider.GetFormat属性provider定义。 如果s包含标志,则货币符号可以出现在style其中NumberStyles.AllowCurrencySymbol
签名 可选符号。
数字 一系列数字,范围从 0 到 9。
. 区域性特定的小数点符号。
fractional-digits 一系列数字,范围从 0 到 9。

style 参数指定参数的允许格式 s ,并且可以是一个或多个 NumberStyles 使用按位 OR 运算组合的枚举常量。 如果 style 为 null, s 则使用 NumberStyles.Number 样式进行解释。

参数provider是一个IFormatProvider实现,如或NumberFormatInfoCultureInfo对象。 该 provider 参数提供分析中使用的区域性特定信息。 provider如果是null,则使用线程当前区域性。

对象 Decimal 具有 29 位精度。 如果s表示数字的位数超过 29 位,但具有小数部分,并且位于该数字范围内MaxValueMinValue,并且该数字是舍入的,而不是截断的,则使用舍入到最接近的 29 位数字。

如果在分析操作期间在参数中 s 遇到分隔符,并且适用的货币或数字小数和组分隔符相同,则分析操作假定分隔符是小数分隔符,而不是组分隔符。 有关分隔符的详细信息,请参阅CurrencyDecimalSeparatorNumberDecimalSeparatorCurrencyGroupSeparatorNumberGroupSeparator

另请参阅

适用于