ios千分位和小数精度位数处理

ios千分位和小数精度位数处理

- (NSString *)formatDecimalNumber:(NSString *)string {
    if (!string || string.length == 0) {
        return string;
    }
    NSNumber *number = @([string doubleValue]);
    NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
    formatter.numberStyle = NSNumberFormatterDecimalStyle;
    formatter.positiveFormat = @"###,##0.000";
    NSString *amountString = [formatter stringFromNumber:number];
    return amountString;
}
NSString *string = @"122234364.23234";
NSString *s1 = [self formatDecimalNumber:string];
NSLog(@"%@", s1); # 122,234,364.232
上一篇:Subsets II - LeetCode


下一篇:APP开发用什么框架最好?这5大框架,开发者必备神器