Click here to Skip to main content
15,910,603 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
Hi there, I am getting problem two add two tex tbox and put the result in the third text box. Here is my code. It concatenate and put it the third textbox rather than to add it.

Double news;
news = Double.Parse(txtAmt.Text) + Double.Parse(txtOldSalary.Text);
txtNewSalary.Text = news.ToString();
Posted

You can try this..

MIDL
Double news;
news = Convert.ToDouble(txtAmt.Text) + Convert.ToDouble(txtOldSalary.Text);
txtNewSalary.Text = news.ToString();
 
Share this answer
 
Comments
Mikiyas Abebe 12-Oct-10 8:22am    
It tried it but it has the same problem
Dave Paras 12-Oct-10 9:08am    
Can you provide sample data you are using in txtAmt and txtOldSalary textbox
Mikiyas Abebe 13-Oct-10 0:20am    
for example 10 + 23 it put the answer like this 1023
Dave Paras 13-Oct-10 0:37am    
steps
----
1. Add three textboxes and button in your form.
2. on button click event paste following code.
---
Double news;
news = Convert.ToDouble(txtAmt.Text) + Convert.ToDouble(txtOldSalary.Text);
txtNewSalary.Text = news.ToString();
---
3. Run program. (F5)
4. Enter 10 in txtAmt textbox
5. Enter 23 in txtOldSalary textbox
6. Click button
7. You'll get result in txtNewSalary textbox, sum of 10 and 23 (33).
Mikiyas Abebe 13-Oct-10 15:39pm    
Actually I put the code in the textchange event of the txtamt. Why it doesn't work for it.
Double abc = Convert.ToDouble(TextBox1.Text.Trim()) + Convert.ToDouble(TextBox2.Text.Trim());


Does that help?
 
Share this answer
 
Comments
CPallini 12-Oct-10 7:48am    
There must be Mr.Univoter, around...
Mikiyas Abebe 12-Oct-10 8:22am    
It tried it but it has the same problem
Double news;
news=Convert.ToDouble(txtAmt.Text) + Convert.ToDouble(txtOldSalary.Text);
txtNewSalary.Text = news.ToString();
 
Share this answer
 
Comments
Mikiyas Abebe 12-Oct-10 8:23am    
It tried it but it has the same problem
simple you can use convert.todouble
 
Share this answer
 
first you convert these two values in double and then add it.

double a=Double.parse(txtAmt.Text);
double b=Double.parse(txtOldSalary.Text);
news=a+b;
txtNews.text=news+"";
 
Share this answer
 
Comments
Mikiyas Abebe 12-Oct-10 8:23am    
It tried it but it has the same problem
All of the above answers are close, but unless you're handling the TextChanged event to ensure that only numeric values are entered as the user types, you could run into problems.

I would do this:

C#
double x1;
double x2;
if (double.TryParse(textBox1.Text, out x1) && double.TryParse(textBox2.Text, out x2)
{
    textBox3.Text = string.Format("{0}", x1 + x2);
}
 
Share this answer
 
v2
Comments
Mikiyas Abebe 12-Oct-10 8:29am    
it the same it doesn't work for me
Eeriepilot 12-Oct-10 14:29pm    
This is the best method!!!
Double abc = Convert.ToDouble(TextBox1.Text.Trim()) + Convert.ToDouble(TextBox2.Text.Trim());
 
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