美文网首页
[iOS]保留两位小数

[iOS]保留两位小数

作者: choici | 来源:发表于2020-03-03 18:37 被阅读0次
1. 四舍五入
CGFloat rounded_up = round(0.355 * 100) / 100;
NSLog(@"%.2lf",rounded_up);
2. 直接进1(天花板函数)
CGFloat rounded_up1 = ceilf(0.355 * 100) / 100;
NSLog(@"%.2lf",rounded_up1);
3. 舍弃后面所有位数(地板函数)
CGFloat rounded_up2 = floor(0.355 * 100) / 100;
NSLog(@"%.2lf",rounded_up2);

相关文章

网友评论

      本文标题:[iOS]保留两位小数

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