本文介绍了如何显示增加值而不是减少值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这个代码可以让我增加两个数字。
I have this code that gives me the increase between two numbers.
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();
它工作正常,直到我输入一些数字反过来。我将首先向您展示它的正确工作方式。
TextBoxLYTHCAS = 321
TextBoxTHCAS = 321
TextBoxHC50 = 93
正如您所看到的,这不是两个数字之间的增加。它等于相同的数字。如何才能获得在TextBoxHC50中显示的增加数字而不显示TextBoxHC50中的减少值?
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?
推荐答案
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 = "";
}
这篇关于如何显示增加值而不是减少值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!