-3

我有小问题,我需要帮助..

所以这是我的问题,我在 c# 中创建了 win 表单并使用 numericupdown 元素插入我的数字,但我无法计算百分比。下面是代码:

private void button8_Click(object sender, EventArgs e)
    {
        int x, y, sum;
        x = Convert.ToInt16(numericUpDown7.Value);
        y = Convert.ToInt16(numericUpDown8.Value);
        sum = x * 3.4528 + 21%;
        textBox5.Text = Convert.ToString(sum);
    }

我需要做的是插入 x 并按下按钮来计算这个公式

例如:x * 3.4528 + 21 % = ???

也许有人可以帮助我。

谢谢大家,谁会帮助我!

4

3 回答 3

0

尝试这个

sum = (x * 3.4528) * 1.21;
于 2014-10-08T11:35:15.260 回答
0

private void button1_Click(object sender, EventArgs e) { double eng, urdu, math, cs, tot, per;

        eng = Convert.ToDouble(txtenglish.Text);
        urdu = Convert.ToDouble(txturdu.Text);
        math = Convert.ToDouble(txtmath.Text);
        cs = Convert.ToDouble(txtcs.Text);

        tot = eng + urdu + math + cs;
        lbltotal.Text = Convert.ToString(tot);

        per = (tot / 400) * 100;
        lblpercent.Text = Convert.ToString(per);
    }
于 2019-03-06T17:21:47.977 回答
-1

首先,您需要使用decimal,floatdouble代替int(您可以在网上找到许多关于每个参考的参考资料,以帮助您确定最适合您的参考资料)。否则,它只会截断答案并删除小数点后的任何内容。其次,您需要使用其他人提到的公式sum = x * 3.4528 * 1.21

于 2014-10-08T12:05:33.647 回答