Click here to Skip to main content
15,896,201 members
Please Sign up or sign in to vote.
3.67/5 (3 votes)
See more:
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:


C#
Session("priceday1") = Label2.Text

 Label14.Text = Session("priceday1") / 44



Please some one help me in this. When I write code in C# it is throwing error. My code in C#


C#
Session["priceday1"] = Label2.Text ;

Label2.Text = Session["priceday1"].ToString() / 44;
Posted
Updated 25-May-11 23:21pm
v2

try this :)
C#
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";
           }
 
Share this answer
 
Comments
suren.info 27-May-11 1:42am    
I hope this is the proper coding for this question
this is Because ur dividing string by 44 as ur converting ur session in string.

C++
Label2.Text = Session["priceday1"].ToString() / 44;


Remove .ToString() from above line and try like

C++
Label2.Text = (Convert.Toint32( Session["priceday1"] )/ 44).ToString();
 
Share this answer
 
v3
Comments
parmar_punit 26-May-11 6:41am    
nice answer, my 5
Ashishmau 26-May-11 7:12am    
Thanx
Try this

C#
decimal priceday1 = (decimal) Session["priceday1"] / 44;
Label2.Text = priceday1.ToString("C");
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900