15,920,704 members
See more:
I have this code that gives me the increase between two numbers.
C#
```int k = Convert.ToInt32(TextBoxLYTHCAS.Text.Replace(",", ""));
int l = Convert.ToInt32(TextBoxTHCAS.Text.Replace(",", ""));
TextBoxHC50.Text = Convert.ToString(Math.Round((Math.Abs(l - k)) * 100.0 / ((k))));
TextBoxHC50.Text = Math.Round(Convert.ToDouble(TextBoxHC50.Text), 2).ToString();```

It works fine until I entered in some numbers the other way around. I will show you first the correct way it works.

TextBoxLYTHCAS = 321
TextBoxTHCAS = 321
TextBoxHC50 = 93

As you can see this is not an increase between two numbers. It is equal to the same number. How can I just get the increase number to display in TextBoxHC50 and not show the decrease value in TextBoxHC50?
Posted
Sergey Alexandrovich Kryukov 13-Nov-14 16:29pm
Not clear what "increase between two numbers" should mean. Don't use convert. Don't use Round (why?)...
—SA
Computer Wiz99 13-Nov-14 20:58pm
I'm sorry I don't follow you.
Sergey Alexandrovich Kryukov 13-Nov-14 22:53pm
—SA
Kiran Wilson 13-Nov-14 23:17pm
I am getting 0 in TextBoxHC50, while entering 321 in TextBoxLYTHCAS and TextBoxTHCAS. Can you please clarify your example..
Computer Wiz99 14-Nov-14 5:53am
Okay, now can you do the same thing and put 4461 into TextBooxLYTHCAS and put 321 in TextBoxTHCAS. You will get 93. 93 is a decrease percentage from 4461. How can I correct this error? I know the calculations is doing what it is suppose to do but if a value that is entered into TextBoxTHCAS is less than the value in TextBoxLYTHCAS do not calculate. Is that possible?

## Solution 2

If I understand your question correctly, then you want to show the difference in third text box only when value of second text box is greater than first text box and don't want to show the result if case is reverse (second text box value < first text box value)

here is the code -
C#
```int k = Convert.ToInt32(TextBoxLYTHCAS.Text.Replace(",", ""));
int l = Convert.ToInt32(TextBoxTHCAS.Text.Replace(",", ""));
if (l >= k)
{
TextBoxHC50.Text = Convert.ToString(Math.Round((Math.Abs(l - k)) * 100.0 / ((k))));
TextBoxHC50.Text = Math.Round(Convert.ToDouble(TextBoxHC50.Text), 2).ToString();
}
else
{
TextBoxHC50.Text = "";
}```