# Thread: Problem with two Values

1. ## Problem with two Values

HTML Code:
``` private void profitbefore()
{
decimal final = 0;
decimal fullfinal = 0;
if(decimal.TryParse(txtprofitbefore.Text,out final) && decimal.TryParse(txtfinal.Text,out fullfinal))
{

decimal finalfull = final - fullfinal;
txtbeforeexp.Text = finalfull.ToString("#,##0.00");
}
}```
i have two values in windows from the final value have the negative value when i perform the operation its sum the negative value mathematic that's correct but is there any solution we can covert the nagtive valie into postive i search a lot on stackoverflow but i can't get my right answer

3. ## Re: Problem with two Values

If you always want a positive number consider the following language extension.

Code:
```public static class Extensions
{
public static T ToPositive<T>(this T source) where T : INumber<T>
=> T.IsNegative(source) ? -source : source;
}```
Usage
Code:
```int value = -5;
value = value.ToPositive();```

4. ## Re: Problem with two Values

Don't know if this is any good for you.

Code:
```            int neg = -5;
if(neg < 0)
{
neg = (-neg);
}
MessageBox.Show
(neg.ToString());```

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•

Click Here to Expand Forum to Full Width