objective-c浮点数相除

来源:互联网 发布:网络信贷管理办法 编辑:程序博客网 时间:2024/06/05 00:22

今天在实现一个特性,根据完成的步骤分阶段刷新progress bar。结果发现只有最后一步会刷新进度条,前面完成的步骤都无效

代码是:

- (void) notifyStepDone:(NSString*) content{    doneSteps ++;    float currentProgress = doneSteps/maxSteps;    [_delegate refreshProgressTo:currentProgress WithContent:content];}

调试以后发现,原来在前面的步骤里,currentProgress的值总是0。才想到doneSteps和maxSteps的类型都声明为int,所以1/4,2/4的结果都是0,而不是预期的0.25和0.5