我有一个应用程序显示价格。 价格以这样的方式显示:
[self makePrice];
itemPrice.text = [NSString stringWithFormat:@"%i",tempPrice];
itemPrice.textColor = [UIColor whiteColor];
因此,大值显示为:$ 12123041
我需要它是12,123,041美元
我该怎么做?
感谢。感谢您的帮助 添
答案 0 :(得分:1)
NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
[formatter setNumberStyle:NSNumberFormatterCurrencyStyle];
NSNumber *num = [NSNumber numberWithInt:tempPrice];
NSString *str = [formatter stringFromNumber:num];
itemPrice.text = [NSString stringWithFormat:@"%@",str];
答案 1 :(得分:1)
int tempPrice=123456;
NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
[formatter setNumberStyle:NSNumberFormatterCurrencyStyle];
NSNumber *yourNumber = [NSNumber numberWithInt:tempPrice];
NSString *str = [formatter stringFromNumber:yourNumber];
str = [NSString stringWithFormat:@"%@",str];
NSLog(@"my corrunsy === %@",str);
输出
hiiii === $ 123,456.00