Andy Andy - 14 days ago 6
Objective-C Question

Format accessibility label for price

I use

to format price for voice over. I found that it works fine when no thousands separator used and for certain list of currencies such as US$, €, £, however it doesn't seem to work for any other currencies, e.g. CA$ is pronounced as C-A-Dollar... What's the right way to configure
to get a decent output suitable for voice over?

NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
formatter.numberStyle = NSNumberFormatterCurrencyStyle;
formatter.usesGroupingSeparator = NO;
formatter.currencyCode = @"NOK";

view.accessibilityLabel = [formatter stringFromNumber:@100];

As Carl mentioned below,
can be used. It formats currency based on locale and ignores all other settings even
. With some manual work it can be a suitable alternative!

Example below:

let formatter = NumberFormatter()
formatter.numberStyle = .currencyPlural
formatter.usesGroupingSeparator = false // being entirely ignored :/
formatter.locale = Locale(identifier: "en_CA")

let str = formatter.string(from: 1000.50)!



1,000.50 Canadian dollars


Does NSNumberFormatterCurrencyPluralStyle meet your needs? That is iOS9 and later only, though.