Last active
December 30, 2015 07:48
-
-
Save piaoapiao/6d23ef07f168818548d2 to your computer and use it in GitHub Desktop.
4舍5入 保留小数点后2位
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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