4

I am getting result in string like this $100000. But i want this string value is separated with "," like currency format. E.g.: 1,00,000. How do I format this string value like that? Please give suggestion for this.

Thanking in advance

Paul Sasik
  • 79,492
  • 20
  • 149
  • 189
Nari
  • 213
  • 5
  • 16
  • What you're asking is actually a near-opposite of splitting a string. It is called formatting, and specifically in your case, currency formatting. – Paul Sasik Oct 10 '11 at 14:20
  • 2
    See here http://stackoverflow.com/questions/7284724/is-there-any-easier-way-to-show-currency-formatas-specially-commas-can-i-int/7284807#7284807 – Joe Oct 10 '11 at 14:24

3 Answers3

5

Try something like:

    NSNumberFormatter * formatter = [[[NSNumberFormatter alloc] init] autorelease];
    formatter.numberStyle = NSNumberFormatterCurrencyStyle;
    formatter.currencyCode = @"USD";

    NSString * formattedAmount = [formatter stringFromNumber: @1000000.25];
Ashley Mills
  • 50,474
  • 16
  • 129
  • 160
-1

There are a number of ways to format currency. See here and here for starters. Those links mostly use a floating point number as a starting value for currency formatting. In your case you will also need to parse (maybe also clean up) the string value to make sure it is a valid number that can be formatted for currency. See here for starters on that. There are many, many other examples available from a simple Google search.

Community
  • 1
  • 1
Paul Sasik
  • 79,492
  • 20
  • 149
  • 189
-1
NSNumberFormatter * numberformat = [[[NSNumberFormatter alloc] init] autorelease];
numberformat.numberStyle = NSNumberFormatterCurrencyStyle;
numberformat.currencyCode = @"USD";

NSString * amountformat = [numberformat stringFromNumber: [NSNumber numberWithFloat: 1000000.25]]
Max MacLeod
  • 26,115
  • 13
  • 104
  • 132
girish
  • 900
  • 12
  • 23