我有一个显示价格的应用程序。价格以这种方式显示:
[self makePrice];
itemPrice.text = [NSString stringWithFormat:@"%i",tempPrice];
itemPrice.textColor = [UIColor whiteColor];
结果大值显示为:$ 12123041
我需要它是 12,123,041 美元
我该怎么做?
谢谢。感谢您的帮助蒂姆
我有一个显示价格的应用程序。价格以这种方式显示:
[self makePrice];
itemPrice.text = [NSString stringWithFormat:@"%i",tempPrice];
itemPrice.textColor = [UIColor whiteColor];
结果大值显示为:$ 12123041
我需要它是 12,123,041 美元
我该怎么做?
谢谢。感谢您的帮助蒂姆
NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
[formatter setNumberStyle:NSNumberFormatterCurrencyStyle];
NSNumber *num = [NSNumber numberWithInt:tempPrice];
NSString *str = [formatter stringFromNumber:num];
itemPrice.text = [NSString stringWithFormat:@"%@",str];
嗨,你可以这样做: -
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