绝对值和小数向上、向下取整、四舍五入

abs, fabs, fabsf分别对应整形,float ,double

例如fabs(-0.856) = 0.856;

ios小数向上、下取整,计算结果向上、下取整:

小数向上取整,指小数部分直接进1 x=3.14,ceilf(x)=4

小数向下取整,指直接去掉小数部分 x=3.14,floor(x)=3

小数处理 四舍五入

NSLog(@”%f”,round(12345.6789));//12346.000000
NSLog(@”%f”,round(12345.6749*100)/100);//12345.670000

NSNumber *num = [NSNumber numberWithFloat:12.1250];

NSLog(@”%@”,[NSString stringWithFormat:@”%.2f”,round([num floatValue]*100)/100]);//12.13

猜你喜欢

转载自blog.csdn.net/freetourw/article/details/54908679