1

I'm trying to display a price in cents (99¢) instead of dollars ($0.99) using NSNumberFormatter and a locale.

This code turns a price of 99 cents into the string: $0.99. Is there a way to get NSNumberFormatter to try to use smaller/cent denominations, when possible, instead?

    NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init];
    [numberFormatter setFormatterBehavior:NSNumberFormatterBehavior10_4];
    [numberFormatter setNumberStyle:NSNumberFormatterCurrencyStyle];
    [numberFormatter setLocale:product.priceLocale];
    NSString *formattedPriceString = [numberFormatter stringFromNumber:product.price];
Warpling
  • 2,024
  • 2
  • 22
  • 38

1 Answers1

1

I'm pretty sure there is no easy and general-purpose way to do this. I think you just have to handle it on a case-by-case basis. If you want to localize your app for an international audience, but expect many of your customers to be from the US, you can do something like what I did:

if priceString == "$0.99" && NSLocale.currentLocale().objectForKey(NSLocaleCountryCode) as? String == "US" {
    priceString = "99¢"
}
bugloaf
  • 2,890
  • 3
  • 30
  • 49