上面的答案将转换一个数字,但这里有一种方法可以将nsstring实际转换为货币格式。
- (NSString*) formatCurrencyWithString: (NSString *) string
{
// alloc formatter
NSNumberFormatter *currencyStyle = [[NSNumberFormatter alloc] init];
// set options.
[currencyStyle setFormatterBehavior:NSNumberFormatterBehavior10_4];
// reset style to no style for converting string to number.
[currencyStyle setNumberStyle:NSNumberFormatterNoStyle];
//create number from string
NSNumber * balance = [currencyStyle numberFromString:string];
//now set to currency format
[currencyStyle setNumberStyle:NSNumberFormatterCurrencyStyle];
// get formatted string
NSString* formatted = [currencyStyle stringFromNumber:balance];
//release
[currencyStyle release];
//return formatted string
return formatted;
}