Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

word2number python

# first run in terminal $ pip install word2number

from word2number import w2n

print w2n.word_to_num("two million three thousand nine hundred and eighty four")
# 2003984

print(w2n.word_to_num('two point three'))
# 2.3

print(w2n.word_to_num('112'))
# 112

print(w2n.word_to_num('point one'))
# 0.1

print(w2n.word_to_num('one hundred thirty-five'))
# 135

print(w2n.word_to_num('million million'))
# Error: Redundant number! Please enter a valid number word (eg. two million twenty three thousand and forty nine)
# None

print(w2n.word_to_num('blah'))
# Error: No valid number words found! Please enter a valid number word (eg. two million twenty three thousand and forty nine)
# None
 
PREVIOUS NEXT
Tagged: #python
ADD COMMENT
Topic
Name
9+4 =