Skip to main content

Converts word in string to actual number

Project description

Word to Number

This is a slightly modified version of Akshay Nagpal's w2n package which converts number in words to numeric value. This one is specifically for the Indian Number System. This module converts number in words to numeric value. (eg. eighty four -> 84). It uses Indian Number System (i.e. lakhs and crores). Below is the installation, usage and other details of this module.

Installation

Manual

  • Download the word_to_num.py
  • Paste it in your project location
  • Import and use

Using pip

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

    pip install wordtonum

Usage

Import the module

    from wordtonum import WordToNum

Instantiate the object

    wtn = WordToNum()

Then you can use the to_num method from this class to convert a string to numeric digits, as shown below.

wtn.to_num('two lakhs three thousand nine hundred and eighty four')
203984
wtn.to_num('one hundred thirty-five'))
135

It also supports decimal points

wtn.to_num('twenty six point three')
26.3
wtn.to_num('point one'))
0.1

Most of the errors are raised

wtn.to_num('three thousand lakh'))
ValueError: Malformed number! Please enter a valid number word (eg. two lakhs twenty three thousand and forty nine)
wtn.to_num('Some text'))
ValueError: No valid number words found! Please enter a valid number word (eg. two million twenty three thousand and forty nine)

Bugs/Errors

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, send an email to ashyamzubair@gmail.com with a clear example that can reproduce the issue.

License

The MIT License (MIT)

Copyright (c) 2016 Akshay Nagpal (https://github.com/akshaynagpal)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

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

WordToNum-0.0.2.tar.gz (4.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

WordToNum-0.0.2-py3-none-any.whl (5.0 kB view details)

Uploaded Python 3

File details

Details for the file WordToNum-0.0.2.tar.gz.

File metadata

  • Download URL: WordToNum-0.0.2.tar.gz
  • Upload date:
  • Size: 4.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.18.4 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.25.0 CPython/3.6.4

File hashes

Hashes for WordToNum-0.0.2.tar.gz
Algorithm Hash digest
SHA256 58a31bef868d71c2083dd20d4f7eb7b030198e2ac7c6707d76045147c86d1784
MD5 04d6359f474c53f3acf54e2e5acfeb4e
BLAKE2b-256 0483b771414d8de02ae3569b7665de2526b274aace550a98dc21147433dee0db

See more details on using hashes here.

File details

Details for the file WordToNum-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: WordToNum-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 5.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.18.4 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.25.0 CPython/3.6.4

File hashes

Hashes for WordToNum-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 698b80f9cd8ebe5fd119d3a0822a8060a2a521ef7a58930cef474d60fee76d73
MD5 2da11936a090ecc17dc775444973b493
BLAKE2b-256 d040d21d1fc3bd37e9c91d0190500e182629cba29c2aa6307938b5dbd0d0d317

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