2014-05-13 27 views
0

我試着翻譯的Excel函數:數學裏面戰俘在C#中的另一個數學POW功能

10^(-0,2*7^2+2,74*7+(-4,72)) 

這給了我結果= 45708,8

當我嘗試在我的應用程序來執行此得到錯誤的結果,每次..現在即時通訊卡在結果= 0

我的C#代碼:

destB = (decimal)Math.Pow(10, -0.2 * Math.Pow(Decimal.ToDouble(destB), 2.74 * Decimal.ToDouble(destB)+(-4.72))) 
+0

您的兩個公式的是不一樣的。 'C#'就像'10 ^( - 0.2 * destB ^(2.74 * destB - 4.72))' – MicroVirus

回答

1

什麼是destB?翻譯版本:

Math.Pow(10, -0.2 * 7 * 7 + 2.74 * 7 - 4.72) 

如果7destB,則:

Math.Pow(10, -0.2 * destB * destB + 2.74 * destB - 4.72) 

示例代碼:

double destB = 7; 
double result = Math.Pow(10, -0.2 * destB * destB + 2.74 * destB - 4.72); 
Console.WriteLine(result); 

C# Demo

附:我不會做Math.Pow(destB, 2),因爲它既不會提高可讀性,也不會縮短代碼。

0

這確實是

Math.Pow(10,(-0.2* Math.Pow(7,2)+2.74*7+(-4.72))) 
0

這將是準確的翻譯

var destB = Math.Pow(10, -.2 * Math.Pow(7, 2) + 2.74 * 7 + (-4.72));