其他分享
首页 > 其他分享> > ios千分位和小数精度位数处理

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

标签:NSNumberFormatter,string,ios,千分,NSString,amountString,formatter,小数
来源: https://blog.csdn.net/pureszgd/article/details/122761802