Operator '^' cannot be applied to operands of type 'double' and 'double'
I have this code:
private void t_Tick(object source, EventArgs e)
{
double anInteger;
anInteger = Convert.ToDouble(label1.Text);
anInteger = double.Parse(label1.Text);
double val1;
double val2;
double answer;
double previous_val;
previous_val = Convert.ToDouble(label1.Text);
previous_val = double.Parse(label1.Text);
val1 = anInteger;
val2 = ((((((previous_val ^ 1.001)) / 24) - ((previous_val / 24) / 60)) / 10));
answer = val1 + val2;
label1.Text = answer.ToString();
}
I am getting the error "Operator '^' ca开发者_如何学运维nnot be applied to operands of type 'double' and 'double'" at the line:
val2 = ((((((previous_val ^ 1.001)) / 24) - ((previous_val / 24) / 60)) / 10));
Does anyone have any solutions?
Math.Pow(previous_val, 1.001);
will solve your problem. this is the way how to use powers in .net
^ is bitwise operator XOR. It makes no sense on double type.
What was your intent?
If you are looking to raise a Value1 to the power of Value2
Use:
Math.Pow(Value1,Value2)
In your example:
Math.Pow(previous_val,1.001)
精彩评论