Categories
Python Answers

How to convert number words to integers with Python?

Spread the love

Sometimes, we want to convert number words to integers with Python.

In this article, we’ll look at how to convert number words to integers with Python.

How to convert number words to integers with Python?

To convert number words to integers with Python, we can use the word2number module.

To install it, we run:

pip install word2number

Then we write:

from word2number import w2n

n = w2n.word_to_num("ten million three thousand nine hundred and twenty four")
print(n)

We call w2n.word_to_num with the English number string that we want to convert into a number.

Then we assign the returned number to n.

Therefore, n is 10003924.

Conclusion

To convert number words to integers with Python, we can use the word2number module.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *