2

Possible Duplicate:
Objective-C: How to format string as $ Price

I have an App showing prices. The prices are displayed that way:

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

As a result big values are shown as: $ 12123041

I need it to be $ 12,123,041

How can I do it?

Thanks. Appreciate your help Tim

Community
  • 1
  • 1
Tim White
  • 118
  • 9
  • 1
    This one looks more like it http://stackoverflow.com/questions/7714090/how-to-format-a-currency-string-with-commas – S.P. Oct 05 '12 at 07:37

2 Answers2

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

hi you can do like this way:-

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);

output is

hiiii === $123,456.00

Nitin Gohel
  • 49,482
  • 17
  • 105
  • 144