RangeValidator公式正确可以提高50% [英] RangeValidator Formula Correct to get 50% higher
问题描述
我有一个公式计算,应该找到一个值增加50%。如果值为100且50%增加将为151.我试图查看我的代码是否正确。我对此进行了测试,即使数量相同或小于50%,RangeValidator也会触发。如果代码是否正确,请告诉我。
I have a formula calculation that should find the 50% increase on a value. If a value is 100 and the 50% increase will be 151. I am trying to see if my code of getting this is correct. I tested this and the RangeValidator fires even when the number is the same or less than 50%. Please let me know if the code is correct or not.
int itxtVal13 = Convert.ToInt32(TextBox1.Text);
int iminVal13 = (itxtVal13 * 0);
int imaxVal13 = (itxtVal13 + itxtVal13 * 150 / 100);
RangeValidatorLYFTE4050.MinimumValue = iminVal13.ToString();
RangeValidatorLYFTE4050.MaximumValue = imaxVal13.ToString();
推荐答案
如果你有itxtVal13 = 100并在断点上放置一个断点line
If you have itxtVal13 = 100 and put a breakpoint on the line
RangeValidatorLYFTE4050.MinimumValue = iminVal13.ToString();
然后检查 imaxVal13 $ c的值$ c>你看到了什么?
你计算了250%的itxtVal13而不是150%
将计算更改为
then examine the value of imaxVal13
what do you see?
You have calculated 250% of itxtVal13 not 150%
Either change the calculation to
int imaxVal13 = itxtVal13 + (itxtVal13 * 50 / 100);
或者
int imaxVal13 =(itxtVal13 * 150 / 100);
看到区别?
上面提到的断点就是imaxVal13的断点已经计算好了。您更正的代码(仅限此问题)如下所示:
See the difference?
The breakpoint on the line mentioned was just so that imaxVal13 had already been calculated. Your corrected code (this issue only) will look like:
int itxtVal13 = Convert.ToInt32(TextBox1.Text);
int iminVal13 = (itxtVal13 * 0); // Which = 0 by the way!!
int imaxVal13 = itxtVal13 * (150 / 100);
RangeValidatorLYFTE4050.MinimumValue = iminVal13.ToString();
RangeValidatorLYFTE4050.MaximumValue = imaxVal13.ToString();
这篇关于RangeValidator公式正确可以提高50%的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!