有三个担心,我有。
你在你的表达式中的一部分利用Math.Pow(),但是,你会想在谈话过程中,后来给出的表达式的第一部分使用Math.Sqrt()。
其次,与表达中的括号分组导致表达的错误评价的问题
第三,你将需要你没有一个十进制值,以评估预期的结果数值后使用“d”字符后缀。
以下方程:(0.3D *((0.0015d *(0.793700526d + Math.Sqrt(0.7071068)))+(0.015d * Math.Pow((0.05D 0.05D *),(1D / 3D)))))
编码:
using System;
namespace POW
{
class Program
{
static void Main(string[] args)
{
// Corrected calculation derived from comment conversation given by author
double myCalculation1 = (0.3 * ((0.0015 * (0.793700526 + Math.Sqrt(0.7071068))) + (0.015 * Math.Pow((0.05 * 0.05), (1 / 3)))));
// d suffix used to ensure the non decimal value is treated as a decimal
double myCalculation2 = (0.3 * ((0.0015 * (0.793700526 + Math.Sqrt(0.7071068))) + (0.015 * Math.Pow((0.05 * 0.05), (1d/3d)))));
// Output the value of myPow
Console.WriteLine("The value of myCalculation is: {0}", myCalculation1);
Console.WriteLine("The value of myCalculation is: {0}", myCalculation2);
}
}
}
重要的是,按照惯例,你会希望每个号码后使用“d”后缀。