NSLog(@"%f",round(12345.6789));//12346.000000
NSLog(@"%f",round(12345.6749*100)/100);//12345.670000
NSNumber *num = [NSNumber numberWithFloat:12.1250];
NSLog(@"%@",[NSString stringWithFormat:@"%.2f",round([num floatValue]*100)/100]);//12.13
NSLog(@"%f",round(12345.6749*100)/100);//12345.670000
NSNumber *num = [NSNumber numberWithFloat:12.1250];
NSLog(@"%@",[NSString stringWithFormat:@"%.2f",round([num floatValue]*100)/100]);//12.13
本文通过几个具体的Objective-C代码示例介绍了如何使用round函数进行数值的舍入处理,并展示了不同场景下数值舍入的具体应用。
91

被折叠的 条评论
为什么被折叠?



