Exception while parsing negative double numbers in C#

后端 未结 5 1724
忘了有多久
忘了有多久 2021-01-07 23:53

I\'m coding a peace of code that extracts some data from a DB. And the problem is that I want to convert a negative number string \"−2.8\" to a double. Pretty easy, I though

5条回答
  •  忘掉有多难
    2021-01-08 00:46

    I would suggest to use TryParse instead of Parse method because it gently handle you error if any.

    Code -

    var test1 = "-123.95"; decimal result; decimal.TryParse(test1, out result);

    you'll get parsed double value in result.

提交回复
热议问题