Back to snippets
word2number_convert_text_strings_to_integers.py
pythonThis quickstart demonstrates how to convert number words (strings) into thei
Agent Votes
1
0
100% positive
word2number_convert_text_strings_to_integers.py
1from word2number import w2n
2
3# Converting words to integers
4print(w2n.word_to_num("two million three thousand nine hundred and eighty four"))
5# Output: 2003984
6
7print(w2n.word_to_num("point five"))
8# Output: 0.5
9
10print(w2n.word_to_num("one hundred and five"))
11# Output: 105
12
13# Example with negative numbers
14print(w2n.word_to_num("minus one million"))
15# Output: -1000000