Skip to content

Instantly share code, notes, and snippets.

@piaoapiao
Last active December 30, 2015 07:48
Show Gist options
  • Save piaoapiao/6d23ef07f168818548d2 to your computer and use it in GitHub Desktop.
Save piaoapiao/6d23ef07f168818548d2 to your computer and use it in GitHub Desktop.
4舍5入 保留小数点后2位
NSDecimalNumber *subtotal = [NSDecimalNumber decimalNumberWithString:@"90.7146"];
//保留小数点后两位
NSDecimalNumberHandler*roundUp = [NSDecimalNumberHandler decimalNumberHandlerWithRoundingMode:NSRoundBankers scale:2 raiseOnExactness:NO raiseOnOverflow:NO raiseOnUnderflow:NO raiseOnDivideByZero:YES];
NSDecimalNumber*total = [subtotal decimalNumberByRoundingAccordingToBehavior:roundUp];
NSLog(@"total:%@",total);
NSLog(@"%f", round([[NSStringstringWithFormat:@"%f",12345.6749] floatValue]*100)/100); 这种方式不准
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment