How to format String currency with commas?

I get the result in a string such as $ 100,000. But I want this string value to be separated by "," as a currency format. For example: 1.00,000. How do I format this string value? Please give a suggestion for this.

Thanking in advance

+4
source share
3 answers

Try something like:

NSNumberFormatter * formatter = [[[NSNumberFormatter alloc] init] autorelease]; formatter.numberStyle = NSNumberFormatterCurrencyStyle; formatter.currencyCode = @"USD"; NSString * formattedAmount = [formatter stringFromNumber: @1000000.25]; 
+4
source

There are several ways to format a currency. See here and here for starters. These links mainly use a floating point number as the starting value for formatting the currency. In your case, you will also need to analyze (possibly also clear) the string value to make sure that it is a valid number that can be formatted for the currency. See here for a start. There are many, many other examples available from a simple Google search.

0
source
 NSNumberFormatter * numberformat = [[[NSNumberFormatter alloc] init] autorelease]; numberformat.numberStyle = NSNumberFormatterCurrencyStyle; numberformat.currencyCode = @"USD"; NSString * amountformat = [numberformat stringFromNumber: [NSNumber numberWithFloat: 1000000.25]] 
0
source

All Articles