关于四舍五入

1.只舍不如,保留小数点后两位

    NSString *leavemoney = @"4661998.08";

    NSString *restinterest = @"44818.1283";

    NSString *totalmoney = @"16808934.4083";

    NSString *money = @"38675";

 

    double leavemoneyDouble = [leavemoney doubleValue];

    double restinterestDouble = [restinterest doubleValue];

    double totalmoneyDouble = [totalmoney doubleValue];

    double moneyDouble = [money doubleValue];

    

    NSLog(@"%.2f", floor(leavemoneyDouble*100)/100);

    NSLog(@"%.2f", floor(restinterestDouble*100)/100);

    NSLog(@"%.2f", floor(totalmoneyDouble*100)/100.0);

    NSLog(@"%.2f", floor(moneyDouble*100)/100.0);

2016-11-01 08:55:59.257 四舍五入[11619:4785973] 4661998.08

2016-11-01 08:55:59.258 四舍五入[11619:4785973] 44818.12

2016-11-01 08:55:59.258 四舍五入[11619:4785973] 16808934.40

2016-11-01 08:55:59.259 四舍五入[11619:4785973] 38675.00

 

posted @ 2016-11-01 09:01  iOS张文权  阅读(363)  评论(2编辑  收藏  举报