C#中,操作员'*'不能应用于类型为“双”和“十进制”的操作数 [英] C#, Operator '*' cannot be applied to operands of type 'double' and 'decimal'

查看:158
本文介绍了C#中,操作员'*'不能应用于类型为“双”和“十进制”的操作数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个错误应该是一个简单的人,但我似乎无法使其工作。问题在于,这非常相同的代码工作之前在节目的事实。我不来看看它要在这种情况下,而不是前四的人发送一个错误任何原因。参考下面的代码,并随时为您提供可能,因为它应该让我更好任何批评。如果它的事项,我使用夏普开发2.2



下面是工作代码的例子:

 无效calc2Click(对象发件人,EventArgs五)
{
如果(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(输入两个千伏安和电压或FLA和电压,无效数据输入,MessageBoxButtons.OK);
}

如果(String.IsNullOrEmpty(tb2_kva.Text)及!String.IsNullOrEmpty(tb2_e.Text))
{
十进制X,Y, Z者除外;
X = decimal.Parse(tb2_kva.Text);
Y = decimal.Parse(tb2_e.Text);
Z =(X * 1000)/(1.732050808米* Y); //在十进制的末尾m个允许小数$ B $的乘法b tb2_fla.Text = z.ToString();
tb2_fla.Text = Math.Round(Z,2)的ToString();
}
,否则
{
如果(String.IsNullOrEmpty(tb2_fla.Text)及!String.IsNullOrEmpty(tb2_e.Text))
{
十进制的x,y和z;
X = decimal.Parse(tb2_fla.Text);
Y = decimal.Parse(tb2_e.Text);
Z =(X * Y *1.732050808米)/ 1000; //在十进制的末尾m个允许小数
tb2_kva.Text = Math.Round(Z,2)的ToString的乘法();

}

下面是发送错误的代码示例

 无效Calc4Click(对象发件人,EventArgs五)
{
如果:这个帖子的主题行!(String.IsNullOrEmpty(tb4_fla.Text)及&放大器; String.IsNullOrEmpty(tb4_e.Text)|| String.IsNullOrEmpty(tb4_kw.Text)及String.IsNullOrEmpty(tb4_e.Text)|| String.IsNullOrEmpty(tb4_e。文本))
{//如果价值观不正确输入后,下面的消息框会出现
MessageBox.Show(输入任何一个FLA和电压或功率和电压,无效数据输入,MessageBoxButtons。好);
}


如果(String.IsNullOrEmpty(tb4_fla.Text)及!&安培;!String.IsNullOrEmpty(tb4_e.Text)及和放大器; String.IsNullOrEmpty(tb4_kw的.text))
{//如果用户eneters FLA和电压计算千瓦

十进制X,Y,Z;
X = decimal.Parse(tb4_fla.Text);
Y = decimal.Parse(tb4_e.Text);
Z =(X * Y)*(8 *1.732050808米);
tb4_kw.Text = Math.Round(Z,0)的ToString();

}

如果(String.IsNullOrEmpty(tb4_kw.Text)及!&安培;!String.IsNullOrEmpty(tb4_e.Text)及和放大器; String.IsNullOrEmpty(tb4_fla的.text))
{; //如果用户输入千瓦和电压计算FLA
十进制X,Y,Z;
X = decimal.Parse(tb4_kw.Text);
Y = decimal.Parse(tb4_e.Text);
Z =(1000 * X)/(Y *1.732050808米)* 0.8;
tb4_fla.Text = Math.Round(Z,0)的ToString();
}

}



我感谢所有帮助我能得到。
谢谢你。


解决方案

 0.8米,而不是0.8 


This error should be a simple one but I cant seem to make it work. The problem lies in the fact that this very same code works earlier in the program. I don's see any reason for it to be sending an error on this instance and not the four previous ones. Reference the code below, and feel free to provide any criticism you may have as it should make me better. If it matters, I am using Sharp Develop 2.2.

Here is an example of the code that works:

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();
	}
		else
	{
		if (!String.IsNullOrEmpty(tb2_fla.Text) & !String.IsNullOrEmpty(tb2_e.Text))
	{ 
			decimal x, y, z;
			x = decimal.Parse(tb2_fla.Text);      
			y = decimal.Parse(tb2_e.Text);
			z = (x * y * 1.732050808m) / 1000; //the m at the end of the decimal allows for the multiplication of decimals  
			tb2_kva.Text = Math.Round(z,2).ToString();

	}

Here is the example of the code that sends the error in the subject line of this post:

void Calc4Click(object sender, EventArgs e)
{
		if (!String.IsNullOrEmpty(tb4_fla.Text) && String.IsNullOrEmpty(tb4_e.Text) || String.IsNullOrEmpty(tb4_kw.Text) & String.IsNullOrEmpty(tb4_e.Text) || String.IsNullOrEmpty(tb4_e.Text))
		{	//If values are entered improperly, the following message box will appear
    	MessageBox.Show("Enter either FLA and Voltage or kW and Voltage", "Invalid Data Entry", MessageBoxButtons.OK);
		} 	


		if (!String.IsNullOrEmpty(tb4_fla.Text)&& !String.IsNullOrEmpty(tb4_e.Text)&& String.IsNullOrEmpty(tb4_kw.Text))
		{//If the user eneters FLA and Voltage calculate for kW

			decimal x, y, z;
			x = decimal.Parse(tb4_fla.Text);
			y = decimal.Parse(tb4_e.Text);
			z = (x*y)*(.8 * 1.732050808m);
			tb4_kw.Text = Math.Round(z,0).ToString();

		}				

		if (!String.IsNullOrEmpty(tb4_kw.Text) && !String.IsNullOrEmpty(tb4_e.Text) && String.IsNullOrEmpty(tb4_fla.Text))
		{;//If the user enters kW and Voltage calculate for FLA
			decimal x, y, z;
			x = decimal.Parse(tb4_kw.Text);
			y = decimal.Parse(tb4_e.Text);
			z = (1000 * x)/(y * 1.732050808m)* .8;
			tb4_fla.Text = Math.Round(z,0).ToString();
		}

	}

I appreciate any help that I can get. Thank you.

解决方案

.8m instead of .8

这篇关于C#中,操作员'*'不能应用于类型为“双”和“十进制”的操作数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆