Decimal. Parse string, postfixed by a minus sign

后端 未结 4 951
栀梦
栀梦 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:34

    This is an accepted format for Decimal.Parse. The style option to the Parse method allows for leading and trailing signs.

    Read more: http://msdn.microsoft.com/en-us/library/91fwbcsb.aspx

提交回复
热议问题