How to format a currency String with commas? [duplicate]
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
Try something like:
NSNumberFormatter * formatter = [[[NSNumberFormatter alloc] init] autorelease];
formatter.numberStyle = NSNumberFormatterCurrencyStyle;
formatter.currencyCode = @"USD";
NSString * formattedAmount = [formatter stringFromNumber: @1000000.25];
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.
NSNumberFormatter * numberformat = [[[NSNumberFormatter alloc] init] autorelease];
numberformat.numberStyle = NSNumberFormatterCurrencyStyle;
numberformat.currencyCode = @"USD";
NSString * amountformat = [numberformat stringFromNumber: [NSNumber numberWithFloat: 1000000.25]]
精彩评论