7
Answers

How to convert in Decimal number please

Israel

Israel

9y
558
1
Hi!
 
I need same help. I navigate in internet I didnt find.
How can I convert all these textbox to decimal. Even the last result should display a decimal number.
 
Thanxin advance! 
 
private void lblTotal1_TextChanged(object sender, EventArgs e)
{
decimal d1, d2, d3, d4, total;
decimal.TryParse(lblTotal1.Text, out d1);
decimal.TryParse(lblTotal2.Text, out d2);
decimal.TryParse(lblTotal3.Text, out d3);
decimal.TryParse(lblTotal4.Text, out d4);
 
total = d1 + d2 + d3 + d4;
lblTotal.Text = total.ToString();
}
 
Answers (7)
0
Ramesh  Maruthi

Ramesh Maruthi

NA 6.1k 406.1k 9y
total = decimal.TryParse(d1 + d2 + d3 + d4);
 
lblTotal.Text = total.ToString("F");
 
See the below link, it might helps you :
 
https://msdn.microsoft.com/en-us/library/fzeeb5cd%28v=vs.110%29.aspx 
Accepted
0
Israel

Israel

NA 847 111.8k 9y
@Rakesh
0
Rakesh

Rakesh

NA 7.2k 1.5m 9y
aspx:
<asp:TextBox runat="server" ID='txtvalue'></asp:TextBox>
<asp:Button runat="server" ID='btnconvert' Text='Convert'
onclick="btnconvert_Click" /><br />
<asp:Label runat="server" ID='lblResult'></asp:Label>
C#: ---> code on button event
decimal dec = decimal.Parse(txtvalue.Text);
lblResult.Text = dec.ToString();
0
Ramesh  Maruthi

Ramesh Maruthi

NA 6.1k 406.1k 9y
No problem Buddy :)
0
Israel

Israel

NA 847 111.8k 9y
Easy code and quick respond. Thanx!
0
Ramesh  Maruthi

Ramesh Maruthi

NA 6.1k 406.1k 9y
oops remove that line just use the below line
0
Israel

Israel

NA 847 111.8k 9y
@Ramesh,
 
 Your code work very well. But there is something happen.
When I put this line I receive one message error in red color. But the last result its converted in decimal:
totale = decimal.TryParse (d1 + d2 + d3 + d4); 
Error 1 No overload for method 'TryParse' takes 1 arguments