Xcode iPhone应用程序:如何打印浮动价格



可能的重复项:
Objective-C:如何将字符串格式化为$ Price

我有一个显示价格的应用程序。价格以这种方式显示:

[self makePrice];
itemPrice.text      = [NSString stringWithFormat:@"%i",tempPrice];
itemPrice.textColor = [UIColor whiteColor];

因此,大值显示为: $ 12123041

我需要它是$ 12,123,041

我该怎么做?

谢谢。感谢您的帮助提姆

嗨,

你可以这样做:-

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

NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
[formatter setNumberStyle:NSNumberFormatterCurrencyStyle];
NSNumber *num = [NSNumber numberWithInt:tempPrice];
NSString *str = [formatter stringFromNumber:num];
itemPrice.text = [NSString stringWithFormat:@"%@",str];

相关内容

  • 没有找到相关文章

最新更新