Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSNumberFormatter: spelling out a number with AND particle (British spelling)

The following code:

AVSpeechSynthesizer * speechSynthesizer = [[AVSpeechSynthesizer alloc] init];
AVSpeechUtterance *utterance = [AVSpeechUtterance speechUtteranceWithString: @"112"];
utterance.voice = [AVSpeechSynthesisVoice voiceWithLanguage:@"en-GB"];
speechSynthesizer  speakUtterance:utterance];

results in with the device saying: "one hundred and twelve" (British spelling)

But if instead you transliterate the number 112:

NSString * wordNumber = nil;
NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init];
[numberFormatter setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"en-GB"]];
[numberFormatter setNumberStyle:NSNumberFormatterSpellOutStyle];
wordNumber = [numberFormatter stringFromNumber:@(112)];

now wordNumber contains "one hundred twelve" (without the and particle).

So:

@"112" -> AVSpeechSynthesizer -> "one hundred and twelve"
@"112" -> NSNumberFormatter   -> "one hundred twelve"

How can I transliterate a number with the and particles,i.e, British spelling?

like image 574
joan Avatar asked Apr 07 '14 19:04

joan


1 Answers

I believe you'll need to do this yourself. I haven't been able to produce your desired result or find any resource that allows me to do so.

I've linked to a question that demonstrates how to do this manually.

Is it possible to spell out numbers in words with a separator?

like image 107
Brandon Schlenker Avatar answered Nov 15 '22 04:11

Brandon Schlenker