iOS数字格式化为每隔三位用逗号隔开

2017-04-26  本文已影响241人  何以_aaa
- (void)viewDidLoad {
    [super viewDidLoad];

    double a = 1234355;
    double b = 324546;
    NSString *strA = [self formatNumberDecimalValue:a];
    NSString *strB = [self formatNumberDecimalValue:b];
    NSLog(@"%@---%@",strA,strB);
}
- (NSString *)formatNumberDecimalValue:(double)value {

    NSString * string = [NSNumberFormatter localizedStringFromNumber:[NSNumber numberWithLongLong:value]
                                                         numberStyle:NSNumberFormatterDecimalStyle];
    return string;
}

打印结果:1,234,355---324,546

上一篇下一篇

猜你喜欢

热点阅读