Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove Negative Sign From Textbox

Tags:

c#

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?

like image 921
mahesh Avatar asked Sep 19 '10 15:09

mahesh


People also ask

How do I make a negative number positive C#?

Abs(value) which will convert your negative value to positive.

How do you remove an integer from a sign in Python?

A common math method is abs. This computes absolute values. It removes the negative sign (if there is one) from the number and returns that.


1 Answers

The static Math.Abs method is your friend.

res = Math.Abs(t1 - t2);
like image 124
stakx - no longer contributing Avatar answered Sep 28 '22 08:09

stakx - no longer contributing