comma separated thousand NSString stringWithFormat

萝らか妹 提交于 2019-12-30 00:51:07

问题


Is it possible to display 1000.99 as 1,000.99 using

[NSString stringWithFormat:@"£%0.2f", 1000.99]

Please guide me if I am not on the right track to achieve this?


回答1:


See NSNumberFormatter.

It can handle all your numeric formatting needs and do so in an automatically localized fashion, when used correctly (since currencies around the world are often written with different punctuation & formatting).

In particular, check out the number formatting guide linked to at the top of the class documentation




回答2:


Using NSNumberFormatter:

NSNumberFormatter *numberFormatter = [[[NSNumberFormatter alloc] init] autorelease];
[numberFormatter setNumberStyle: NSNumberFormatterCurrencyStyle];
NSString *numberAsString = [numberFormatter stringFromNumber:[NSNumber numberWithFloat: 1000.99]];
NSLog(@"%@", numberAsString);


来源:https://stackoverflow.com/questions/1853305/comma-separated-thousand-nsstring-stringwithformat

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!