当任何人将带有后缀的字符串解析为 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/