美文网首页
CGFloat和float取x位小数的精度问题

CGFloat和float取x位小数的精度问题

作者: 爱吃萝卜的小蘑菇 | 来源:发表于2019-02-18 11:44 被阅读0次

CGFloat取x位小数时会四舍五入

CGFloat f = 4.165;
NSLog(@"%@", [NSString stringWithFormat:@"结果%.2f",f]);

输出结果为

2019-02-18 11:42:16.635292+0800 ioi[1435:110039] 结果4.17

float取x位小数时只是单纯的去掉之后的位数

float f = 4.165;
NSLog(@"%@", [NSString stringWithFormat:@"结果%.2f",f]);

输出结果为

2019-02-18 11:42:16.635292+0800 ioi[1435:110039] 结果4.16

相关文章

网友评论

      本文标题:CGFloat和float取x位小数的精度问题

      本文链接:https://www.haomeiwen.com/subject/wiqaeqtx.html