如何显示增加值而不是减少值 [英] How to display the increase value and not the decrease value

查看:115
本文介绍了如何显示增加值而不是减少值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个代码可以让我增加两个数字。

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?

推荐答案

如果我正确理解您的问题,那么您想要显示仅当第二个文本框的值大于第一个文本框时,第三个文本框中的差异,如果大小写反转,则不希望显示结果(第二个文本框值<第一个文本框值)



这里是代码 -

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 -
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 = "";
           }


这篇关于如何显示增加值而不是减少值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆