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