关于四舍五入

手机开发 2016-11-01

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

关于四舍五入

相关推荐

展翅飞翔phpBoy00 / 0评论 2013-10-28