转换" 1.79769313486232E + 308"加倍没有发生OverflowException? [英] Convert "1.79769313486232E+308" to double without OverflowException?

查看:884
本文介绍了转换" 1.79769313486232E + 308"加倍没有发生OverflowException?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的字符串1.79769313486232E + 308,我试图将其转换为一个.NET数值(双?),但我得到下面的异常。我使用 Convert.ToDouble()。什么是正确的方式做到这一点的转换?

  

发生OverflowException:值要么过大或过小的双

解决方案

该问题可能是由于这样的事实: Double.MaxValue 被转换为字符串,而当该字符串是输出,而不是所有的数字被输出,相反,它是圆形的。解析这个值溢出了翻番。

使用 Double.TryParse 键,然后在出现故障时检查的字符串1.79769313486232E + 308平等和代 Double.MaxValue 应该是一个快速的解决方法,如果你需要保持串事情是这样的。

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

解决方案

The problem is likely due to the fact that Double.MaxValue was converted to a string, and when the string is output, not all the digits are output, instead it is rounded. Parsing this value overflows the double.

Using Double.TryParse and subsequently checking equality on the string "1.79769313486232E+308" in case of failure and substituting Double.MaxValue should be a quick workaround, if you need to keep the string the way it is.

这篇关于转换" 1.79769313486232E + 308"加倍没有发生OverflowException?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆