小编use*_*480的帖子

转换错误为十进制

我写了这段代码我在if(tot = 100)时得到错误double类型的Literal不能隐式转换为十进制

    //value in textboxes
    decimal p1 = Convert.ToDecimal(TextBox2.Text);
    decimal p2 = Convert.ToDecimal(TextBox3.Text);
    decimal p3 = Convert.ToDecimal(TextBox4.Text);
    decimal p4 = Convert.ToDecimal(TextBox5.Text);
    decimal p5 = Convert.ToDecimal(TextBox6.Text);
    decimal p6 = Convert.ToDecimal(TextBox7.Text);

    //adding all the p's
    decimal tot = p1 + p2 + p3 + p4 + p5 + p6;

    if (tot = 100.00)
    {
     Label2.Text = "Percentage is 100"
     }
        else
        {
            Label2.Text = "Total of percentages is not 100.";
        }
Run Code Online (Sandbox Code Playgroud)

c# type-conversion

0
推荐指数
1
解决办法
710
查看次数

标签 统计

c# ×1

type-conversion ×1