c# - 带后缀的字符串解析失败

标签 c# string parsing decimal

当任何人将带有后缀的字符串解析为 decimal 失败时。

decimal testValue;
decimal.TryParse("5M", NumberStyles.Number, CultureInfo.CurrentCulture, out testValue)

以下解析将返回 false

为什么传入带后缀的字符串时 TryParse 会失败?

最佳答案

因为 Decimal.TryParse does not support it .

Depending on the value of style, the s parameter may include the following elements:

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

Elements in square brackets ([ and ]) are optional. The following table describes each element.

ws: Optional white space. White space can appear at the beginning of s if style includes the NumberStyles.AllowLeadingWhite flag. It can appear at the end of s if style includes the NumberStyles.AllowTrailingWhite flag.

$: A culture-specific currency symbol. Its position in the string is defined by the NumberFormatInfo.CurrencyNegativePattern or NumberFormatInfo.CurrencyPositivePattern properties of the NumberFormatInfo object returned by the IFormatProvider.GetFormat method of the provider parameter. The currency symbol can appear in s if style includes the NumberStyles.AllowCurrencySymbol flag.

sign: An optional sign.

digits: A sequence of digits ranging from 0 to 9.

.: A culture-specific decimal point symbol.

fractional-digits: A sequence of digits ranging from 0 to 9.

关于c# - 带后缀的字符串解析失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34336795/

相关文章:

c# - 如何将 ISO8601 TimeSpan 转换为 C# TimeSpan?

parsing - Rebol 解析中匹配失败的错误消息

c# - ASP.NET MVC 3 : why does it think my class is a complex type?

c# - 扩展 WPF 工具包 - 如何添加对项目的引用?

c# - JsonConverter CanConvert 不接收类型

c# - 如何在razor引擎中的@var后面添加字符串(ASP MVC)

c - 将字符数组解析为指针数组中的单词(C 编程)

c# - 如何优化大型数据集上的 C# mongodb 查询?

ruby - 通过文本解析以在 Ruby 1.9.x 中查找 html 标签

string - ResponseWriter.Write 和 io.WriteString 有什么区别?