相关疑难解决方法(0)

C#,运算符'*'不能应用于'double'和'decimal'类型的操作数

这个错误应该是一个简单的错误,但我似乎无法使它工作.问题在于这个相同的代码在程序的早期工作.我没有看到任何理由在这个实例上发送错误而不是之前的四个错误.参考下面的代码,随时提供任何批评,因为它应该让我更好.如果重要,我正在使用Sharp Develop 2.2.

以下是有效代码示例:

void calc2Click(object sender, EventArgs e)
{
    if (!String.IsNullOrEmpty(tb2_fla.Text) & String.IsNullOrEmpty(tb2_e.Text) | String.IsNullOrEmpty(tb2_fla.Text) & String.IsNullOrEmpty(tb2_e.Text) | String.IsNullOrEmpty(tb2_e.Text))
    {
        MessageBox.Show("Enter either kVA and Voltage or FLA and Voltage", "Invalid Data Entry", MessageBoxButtons.OK);
    }       

        if (!String.IsNullOrEmpty(tb2_kva.Text) & !String.IsNullOrEmpty(tb2_e.Text))
    { 
            decimal x, y, z;
            x = decimal.Parse(tb2_kva.Text);      
            y = decimal.Parse(tb2_e.Text);
            z = (x * 1000) / (1.732050808m * y); //the m at the end of the decimal allows for the multiplication of decimals    
            tb2_fla.Text = z.ToString();
            tb2_fla.Text = Math.Round(z,2).ToString();
    } …
Run Code Online (Sandbox Code Playgroud)

c# decimal multiplying

11
推荐指数
1
解决办法
4万
查看次数

标签 统计

c# ×1

decimal ×1

multiplying ×1