出於某種原因,我下面的代碼行返回一個0公式不要算計
int bac = [food.text intValue] * 12 * 0.042 * 5.14/[weight.text intValue] * 0.73;
我似乎無法找出原因。食物和體重都是UITextFields。任何幫助將非常感激。
它與int需要成爲一個浮點數有什麼關係嗎?或雙?
這裏是我的整個方法:
-(IBAction) calcBac {
float bac = [food.text floatValue] * 12 * 0.042 * 5.14/[weight.text floatValue] * 0.73;
NSString *msg = [[NSString alloc] initWithFormat: @"Results: You're BAC is %d", bac];
result.text = msg;
[msg release];
}
給出你獲得零的'food.text'和'weight.text'的例子。 – 2012-01-05 05:05:39