必知的三個(gè)C函數(shù)
ceil(x)返回不小于x的最小整數(shù)值(然后轉(zhuǎn)換為double型)。
floor(x)返回不大于x的最大整數(shù)值。
round(x)返回x的四舍五入整數(shù)值。
上面就是天花板函數(shù)、地板函數(shù)、四舍五入函數(shù)。
保留兩位小數(shù),四舍五入
//保留兩位小數(shù),四舍五入CGFloat rounded_up = round(0.355*100) /100;? ? NSLog(@"%.2lf",rounded_up);
//保留兩位小數(shù),直接進(jìn)1(天花板函數(shù))CGFloat rounded_up1 = ceilf(0.355*100) /100;? ? NSLog(@"%.2lf",rounded_up1);
//保留兩位小數(shù),舍棄后面所有位數(shù)。(地板函數(shù))CGFloat rounded_up2 = floor(0.355*100) /100;? ? NSLog(@"%.2lf",rounded_up2);

63C695AC-1EF9-4915-9BA2-2026B08437A3.png
//保留兩位小數(shù),四舍五入CGFloat rounded_up = round(0.354*100) /100;? ? NSLog(@"%.2lf",rounded_up);//保留兩位小數(shù),直接進(jìn)1(天花板函數(shù))CGFloat rounded_up1 = ceilf(0.354*100) /100;? ? NSLog(@"%.2lf",rounded_up1);//保留兩位小數(shù),舍棄后面所有位數(shù)。(地板函數(shù))CGFloat rounded_up2 = floor(0.354*100) /100;? ? NSLog(@"%.2lf",rounded_up2);
