-5

string金钱价值

NSString *money = "123456789";

我想印钱,比如 123,456,789

4

3 回答 3

2

Nik回复了

使用 NSNumberFormatter。

具体来说

NSNumberFormatter *formatter = [NSNumberFormatter new];
[formatter setNumberStyle:NSNumberFormatterDecimalStyle]; // this line is important!

NSString *formatted = [formatter stringFromNumber:[NSNumber numberWithInteger:2000000]];

[formatter release];

默认情况下 NSNumberFormatter 使用当前语言环境,因此默认情况下分组分隔符设置为正确的值。关键是要记住设置数字样式。

请参考这些链接

1-链接#one

2-链接#Two

于 2013-06-26T07:02:34.583 回答
0

try this:

NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
[formatter setNumberStyle:NSNumberFormatterCurrencyStyle];   //here is money style... or or you can also set your other style
NSString *str = [formatter stringFromNumber:[NSNumber numberWithInt:123456789]];

and also refer following links...

  1. Objective-C: How to format string as $ Price
  2. Using NSNumberFormatter to format currency in output UILabel
于 2013-06-26T07:08:52.783 回答
0

为胜利而战

NSString *decNumberString =  [NSNumberFormatter localizedStringFromNumber:[NSNumber numberWithInteger:[str integerValue]]
                                                     numberStyle:NSNumberFormatterDecimalStyle];
于 2013-06-26T07:04:00.820 回答