在会话计算中将字符串转换为int.
问题描述:
请检查我在VB.NET中是否有将会话变量转换为美元金额的计算方法.该代码在VB.NET中运行,但在C#中引发错误.我的代码是:
Please check I have a convert session variable into dollar amount calculation in VB.NET. The code is running in VB.NET but in C# it is throwing an error. My code is:
Session("priceday1") = Label2.Text
Label14.Text = Session("priceday1") / 44
请有人帮助我.当我用C#编写代码时,会引发错误.我在C#中的代码
Please some one help me in this. When I write code in C# it is throwing error. My code in C#
Session["priceday1"] = Label2.Text ;
Label2.Text = Session["priceday1"].ToString() / 44;
答
尝试一下:)
try this :)
Session["priceday1"] = "5464";
// Session["priceday1"] = 5464;
double finalPrice;
if (Double.TryParse(Session["priceday1"].ToString(), out finalPrice))
{
finalPrice = finalPrice / 44;
Label1.Text = finalPrice.ToString();
}
else
{
Label1.Text = "Invalid";
}
这是因为ur将字符串除以44会导致您在字符串中转换会话.
this is Because ur dividing string by 44 as ur converting ur session in string.
Label2.Text = Session["priceday1"].ToString() / 44;
从上面的行中删除.ToString(),然后尝试像
Remove .ToString() from above line and try like
Label2.Text = (Convert.Toint32( Session["priceday1"] )/ 44).ToString();
试试这个
Try this
decimal priceday1 = (decimal) Session["priceday1"] / 44;
Label2.Text = priceday1.ToString("C");