Value
is int
variable and therefore TestP1.corAns / 52
will be rounded to some integer value even if TestP1.corAns
is a real number (float
or double
). Moreover, if TestP1.corAns
is also integer you will have integer division. Ultimately the value of the value
variable will be rounded to the biggest integer, smaller than the result of your operations, presumably to 0 since you want percents. In order to avoid that, first make sure to get real number after division and that multiply that number by 100. Use something like this:
double value;
value = TestP1.corAns / 52.0 * 100.0;
ProgressBar pBar = new ProgressBar();
pBar.Value = (int)value;
label2.Text = Convert.ToString(value) + "%";
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…