我做下面的代碼時,他們打我的應用程序計算按鈕:無法做計算並獲得打印出標記
float sqft = ([textfield1.text floatValue]);
float thick= ([textfield2.text floatValue]);
float cos = ([textfield3.text floatValue]);
float eff = ([textfield4.text floatValue]);
float num = ((thick*.5)*sqft)/eff;
float cost = (num*cos);
float costft = (cost/sqft);
label1.text = [NSString stringWithFormat:@"%2.f",num];
label2.text = [NSString stringWithFormat:@"%2.f",cost];
label3.text = [NSString stringWithFormat:@"%2.f",costft];
當我做這個標籤只返回零。我已經設置標籤爲maually作爲字符串只是爲了看看它是否是代表團的事情,但我無法弄清楚爲什麼我的公式只返回零。
也許你想'.2f'?另外,確保'eff!= 0.0f'和'sqft!= 0.0f'。此外,'NSLog'的值或'num','cost'和'costft'確保它們給你正確的值。 – msgambel 2013-05-04 05:15:13
請發佈數量,成本,costft的NSLog值。 – 2013-05-04 05:23:09
@VenkatManoharPerepa,sqft的數據類型是: - > float sqft =([textfield1.text floatValue]); – 2013-05-04 05:28:10