在会话计算中将字符串转换为int. [英] convert string to int in session calcu.

查看:68
本文介绍了在会话计算中将字符串转换为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");


这篇关于在会话计算中将字符串转换为int.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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