转换为ToDouble时出错 [英] Error while converting to ToDouble

查看:106
本文介绍了转换为ToDouble时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好



以下是我的代码



Hi all

Below is my code

double l = Convert.ToDouble(lbll.Content);





以下是我得到的错误





below is the error i am getting

Input string was not in a correct format.





请告诉我这里的问题



Please tell me the problem here

推荐答案

检查lbll.Content的值,它不是有效的double。您应该使用 Double.TryParse方法 [ ^ ]。如果转换成功与否则返回,将默认值传递给参数并且不抛出异常。
Check the value of lbll.Content, it is not a valid double. You should use Double.TryParse Method[^] instead. It returns if conversion was successful or not , passes default value to your parameter and does not throw exception.


lbll.Content的值不能转换为double。



首先尝试解析如下:

The value of the lbll.Content can't converted into double.

Try a parse first as follows:
double value;
if(!Double.TryParse(lbll.Content, out value))
{
    //not a double value
}

else
{
    //you can use your double value here
}


这篇关于转换为ToDouble时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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