【发布时间】:2011-08-21 05:28:57
【问题描述】:
我几乎是获得两个整数的百分比的一半,我只需要帮助解决最后一个障碍,这是我的编码到目前为止低于它的工作,但有时它就像是 = 50 和否 = 20% 应该是50/50。
int yes;
int no;
//Work out percentages
if ([VotedAnswer.text isEqualToString:@"No"]){
yes = [currentYes intValue];
no = [currentNo intValue] + 1;
}else{
yes = [currentYes intValue] + 1;
no = [currentNo intValue];
}
int total = yes + no + 1;
int pcntYes = (yes *100) / total;
int pcntNo = (no *100) / total;
float barNo = pcntNo / 100.0f;
float barYes = pcntYes / 100.0f;
//Set percent labels
yesPercent.text = [NSString stringWithFormat:@"%d%%", pcntYes];
noPercent.text = [NSString stringWithFormat:@"%d%%", pcntNo];
//Set Percent Bars
YesProgress.progress = barYes;
NoProgress.progress = barNo;
【问题讨论】:
标签: iphone objective-c math int