C# 对来自xml的数据执行乘法时遇到问题

C# 对来自xml的数据执行乘法时遇到问题,c#,asp.net,xml,google-api,xmldocument,C#,Asp.net,Xml,Google Api,Xmldocument,嗨,我在乘以从谷歌金融api检索到的数据时遇到了问题。我知道我现在所做的是错误的,所以我想要一些关于如何去做的指针和一些例子 string url = "http://www.google.com/ig/api?stock=" + Server.UrlEncode(symbol1.Text); XmlDocument xdoc = new XmlDocument(); xdoc.Load(url); currentPrice1.Text = GetData(

嗨,我在乘以从谷歌金融api检索到的数据时遇到了问题。我知道我现在所做的是错误的,所以我想要一些关于如何去做的指针和一些例子

    string url = "http://www.google.com/ig/api?stock=" + Server.UrlEncode(symbol1.Text);
     XmlDocument xdoc = new XmlDocument();
     xdoc.Load(url);
     currentPrice1.Text = GetData(xdoc, "last");
     int quantity = 50;
     int currentPrice = int.Parse(currentPrice1.Text);
     int totalValue = quantity * currentPrice;
获取数据方法

private string GetData(XmlDocument doc2, string strElement)
{

    XmlNodeList xnodelist5 = doc2.GetElementsByTagName(strElement);
    XmlNode xnode5 = xnodelist5.Item(0);
    return Get_Attribute_Value(xnode5, "data");

}
错误

可能是数据属性的值为非数字或未指定。使用TryParse方法或使用try..catch.包装代码。。街区

 decimal currentPrice;
 if(decimal.TryParse(currentPrice1.Text, out currentPrice))
  {
     //
   }

如果数据属性的值为整数,则使用
int.TryParse

查看代码当前价格1的打印屏幕。文本可能为空或非数字

那就请吧

int currentPrice = 0;

if(!string.IsEmptyOrNull(currentPrice1.Text))
{
   int price = 0;
   if(int.TryParse(currentPrice1.Text, out price))
   {
       currentPrice = price ;
   }
}

请告诉我们你做乘法时的错误是的,我补充说谢谢你提醒我!谢谢你,伙计,你是个救命恩人。数据属性是decimal。