Exception while parsing negative double numbers in C#

后端 未结 5 1700
忘了有多久
忘了有多久 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:30

    Substitute a hyphen for the dash:

    var climateString = "−2.8".Replace ("−", "-");
    var number = double.Parse(climateString);
    

    (You might want to be on the lookout for other strange characters coming out of that database, though.)

提交回复
热议问题