Skip to main content

Convert number words eg. three hundred and forty two to numbers (342).

Project description

travis_pic codecov_pic

Word to Number

This is a Python module to convert number words (eg. twenty one) to numeric digits (21). It works for positive numbers upto the range of 999,999,999,999 (i.e. billions).

Installation

Please ensure that you have updated pip to the latest version before installing word2number.

You can install the module using Python Package Index using the below command.

pip install word2number

Make sure you install all requirements given in requirements.txt

pip install -r requirements.txt

Usage

First you have to import the module using the below code.

from word2number import w2n

Then you can use the word_to_num method to convert a number-word to numeric digits, as shown below.

>>> 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

Bugs/Errors

Please ensure that you have updated pip to the latest version before installing word2number.

If you find any bugs/errors in the usage of above code, please raise an issue through Github. If you don’t know how to use Github or raise an issue through it, I suggest that you should learn it. Else, send an email to akshay2626@gmail.com with a clear example that can reproduce the issue.

Contributors

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

word2number-1.0.zip (9.4 kB view details)

Uploaded Source

File details

Details for the file word2number-1.0.zip.

File metadata

  • Download URL: word2number-1.0.zip
  • Upload date:
  • Size: 9.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for word2number-1.0.zip
Algorithm Hash digest
SHA256 72770e04aa5d74fe5c87b42596d459aa4571561b9f0b6e17358ace3075aeb321
MD5 e1ccc4ba2c17c1655e1dd8714c297543
BLAKE2b-256 f4d44e18534181f5727a53349043c62c8accb85b7fe613a19e0e788ae9f6ee19

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page