Skip to content

Instantly share code, notes, and snippets.

@bruckhaus
Created January 7, 2015 07:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bruckhaus/1f03a7760875fd170bea to your computer and use it in GitHub Desktop.
Save bruckhaus/1f03a7760875fd170bea to your computer and use it in GitHub Desktop.
def in_words(i):
d = NumberLetterCounts.NUMBER_WORDS
words = ''
if i >= 1000:
thousands = i / 1000
i %= 1000
words = d[thousands] + " thousand"
if i > 0:
words += " "
if i >= 100:
hundreds = i / 100
i %= 100
words += d[hundreds] + " hundred"
if i > 0:
words += " and "
if i >= 20:
tens = i / 10
i %= 10
words += d[tens * 10]
if i > 0:
words += "-"
if i > 0:
words += d[i]
return words
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment