Numbers in words

Nigel Garvey has posted a fine script for converting numbers into words (123 in to “one hundred…”, etc) in the Code Exchange forum here: http://macscripter.net/viewtopic.php?id=32033. I don’t want to steal his thunder, but it’s a good example of the type of thing ASObjC makes fairly easy, in this case courtesy of NSNumberFormatter, so I thought I’d post the code here.

Getting a number as words in your existing locale is a one-liner:

set someNumber to 12345678
set theString to current application's NSNumberFormatter's localizedStringFromNumber_numberStyle_(someNumber, current application's NSNumberFormatterSpellOutStyle)

To do it with some other locale it’s a little more work:

set someNumber to 12345678
set myLocale to current application's NSLocale's alloc()'s initWithLocaleIdentifier_("fr_FR")
set aFormatter to current application's NSNumberFormatter's alloc()'s init()
tell aFormatter
	setLocale_(myLocale)
	setNumberStyle_(current application's NSNumberFormatterSpellOutStyle)
	set theString to stringFromNumber_(someNumber)
end tell