开发者

get the NSNumberFormatter to spell out the currency, when formatting a price

I'm implementing in-app purchases in my app right now. In order to get the localized price I 开发者_开发技巧do the following:

NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init];
  [numberFormatter setFormatterBehavior:NSNumberFormatterBehavior10_4];
  [numberFormatter setNumberStyle:NSNumberFormatterCurrencyStyle];
  [numberFormatter setLocale:self.priceLocale];
  NSString *formattedString = [numberFormatter stringFromNumber:self.price];
  [numberFormatter release];
  return formattedString;

This works fine. However I would like to get a string that's convertible to a ASCII string. So is there a way to let the number formatter spell out the currency. e.g. "0.99€" would become "0.99 Eur" or "0.99 Euro".


There is a way to do that by replacing ¤ in formatter's format:

NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init];
[numberFormatter setFormatterBehavior:NSNumberFormatterBehavior10_4];
[numberFormatter setNumberStyle:NSNumberFormatterCurrencyStyle];
[numberFormatter setLocale:self.priceLocale];
NSString *currencyString = [numberFormatter internationalCurrencySymbol];
NSString *posFormat = [numberFormatter positiveFormat];
formatterFormat = [formatterFormat stringByReplacingOccurrencesOfString:@"¤" withString:currencyString];
[numberFormatter setPositiveFormat:posFormat];
NSString *formattedString = [numberFormatter stringFromNumber:self.price];
[numberFormatter release];
return formattedString;
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜