It's certainly possible. Here's one I wrote for English (in Python, sorry, started translating it to JS but stopped halfway for some reason):
Code:
units = ["", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"]
specunits = { "ten-one" : "eleven", "ten-two" : "twelve", "ten-three" : "thirteen", "ten-four" : "fourteen", "ten-five" : "fifteen", "ten-six" : "sixteen", "ten-seven" : "seventeen", "ten-eight" : "eighteen", "ten-nine" : "nineteen" }
tens = ["", "ten", "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety"]
def num_to_english(num):
try:
num = int(num)
except ValueError:
return "Invalid input."
if num < -999 or num > 999:
return "Invalid input."
if num == 0:
return "zero"
if num < 0:
num = num * -1;
minus = "minus "
else:
minus = ""
nunits = num % 10
ntens = int(math.floor((num % 100) / 10))
nhunds = int(math.floor(num / 100))
if tens[ntens] and units[nunits]:
tandu = "%s-%s" % (tens[ntens], units[nunits])
else:
tandu = "%s%s" % (tens[ntens], units[nunits])
if tandu in specunits.keys():
tandu = specunits[tandu]
thunds = units[nhunds]
if thunds:
thunds = "%s hundred " % thunds
if units[nhunds]:
if (tens[ntens] or units[nunits]):
thunds = "%sand " % thunds
else:
tandu = ""
return minus + thunds + tandu
It still uses tabs, I must've written this ages ago :-\
Bookmarks