Decimal. Parse string, postfixed by a minus sign

后端 未结 4 923
栀梦
栀梦 2021-01-17 12:01
decimal decimalVal;
Decimal.TryParse(\"123-\", out decimalVal);
Console.WriteLine(decimalVal); // -123

Why do \"123-\" string parsed this way?

4条回答
  •  天涯浪人
    2021-01-17 12:44

    NumberStyles.Number enumerator is used by default:

    Indicates that the AllowLeadingWhite, AllowTrailingWhite, AllowLeadingSign, AllowTrailingSign, AllowDecimalPoint, and AllowThousands styles are used. This is a composite number style

    http://msdn.microsoft.com/en-us/library/system.globalization.numberstyles.aspx

提交回复
热议问题