开发者

How to format a currency String with commas? [duplicate]

开发者 https://www.devze.com 2023-04-11 19:17 出处:网络
This question already has answers he开发者_高级运维re: IS there any easier way to show $ currency format?(As specially commas) Can I integrate RE with Objective C code?
This question already has answers he开发者_高级运维re: IS there any easier way to show $ currency format?(As specially commas) Can I integrate RE with Objective C code? (2 answers) Closed 9 years ago.

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]]
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号