Alex Rivera | Logout

Remove Negative Sign From Textbox

Asked 2010-09-19T15:47:53.493
12

Software Utilize C#, VS-2005

How to Remove Nagative Sign From Textbox. my code is:

Private void button1_Click(object sender, EventArgs e)
{
        decimal t1 = 0;
        decimal t2 = 0;
        decimal res = 0;
        t1 = Convert.ToDecimal(textBox1.Text);
        t2 = Convert.ToDecimal(textBox2.Text);
        res = t1 - t2;
        textBox3.Text = res.ToString();
 }

if t1 have value 12000 and t2 have value 20000. so result is 12000-20000 = -8000

I want to remove (-) sign from textbox. How can i do that?

c#
Edit
Report

2 Answers

18

The static Math.Abs method is your friend.

res = Math.Abs(t1 - t2);
answered 2010-09-19T15:48:37.360
2

You can take the absolute value of the result of the subtraction.

res = Math.Abs(res)
answered 2010-09-19T15:49:30.797

Your Answer