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

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位小数的精度问题)