2014-04-26 31 views
1

我是一名初學者,並且有一個問題,我有以下代碼,想要輸入兩個文本字段中的兩個值,公式來自我的Java代碼,但在Objective-C中不起作用,將Java表達式/公式轉換爲Objective-C

如何更改以下內容以使其在Objective-C中工作?這裏

double phWert = [self.phWert.text doubleValue]; 
double khWert = [self.khWert.text doubleValue]; 

double co2Ergebnis=Math.floor((7.90+Math.log(khWert/(2.8*phWert))/Math.log(10))*100)/100; 

self.co2Wert.text = [NSString stringWithFormat:@"%f", co2Ergebnis]; 

問題顯然是數學/math.floor/math.log

回答

1

通過以下方式更改代碼:

double co2Ergebnis=floor((7.90+log(khWert/(2.8*phWert))/log(10))*100.0)/100.0; 

不要忘記在你的頭文件math.h中。

+0

嗨我以前試過,但結果是錯誤的。 – Heisenberg

+0

khWert 7和ph 7的結果在這裏是7.450000,但是,正確的結果是19 – Heisenberg

+0

現在嘗試通過將精確點添加到100.請參閱更新的答案。 – Apurv

相關問題