Convert “1.79769313486232E+308” to double without

2020-02-01 18:02发布

I have this string "1.79769313486232E+308" and am trying to convert it to a .NET numeric value (double?) but am getting the below exception. I am using Convert.ToDouble(). What is the proper way to do this conversion?

OverflowException: Value was either too large or too small for a Double

标签: c# .net double
7条回答
smile是对你的礼貌
2楼-- · 2020-02-01 18:58

Demonstrates the issue and a solution:

var s = double.MaxValue.ToString();
double d;
if (!double.TryParse(s, out d)) {
    d = s.Equals(double.MaxValue) ? double.MaxValue : double.MinValue;
}
查看更多
登录 后发表回答