四舍五入保留两位小数
程序员文章站
2024-01-10 15:59:28
...
//保留两位小数,四舍五入 CGFloat rounded_up = round(0.355 * 100) / 100; NSLog(@"%.2lf",rounded_up);
//保留两位小数,直接进1(天花板函数) CGFloat rounded_up1 = ceilf(0.355 * 100) / 100; NSLog(@"%.2lf",rounded_up1);
//保留两位小数,舍弃后面所有位数。(地板函数) CGFloat rounded_up2 = floor(0.355 * 100) / 100; NSLog(@"%.2lf",rounded_up2);
转载于:https://www.jianshu.com/p/d339b02b44f4