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.word_to_num 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.4.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.4-py3-none-any.whl (4.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: WordToNum-0.0.4.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.4.tar.gz
Algorithm Hash digest
SHA256 2b4601410338cf4957c8719376e0d9353b6a478449f691d2337fe7fb853e6592
MD5 17d5ada61353886c1801edea172eb870
BLAKE2b-256 6a3b91bbd9b717e1eaeb005b40ee1709a55bef0085a11125b944515fb1b07e66

See more details on using hashes here.

File details

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

File metadata

  • Download URL: WordToNum-0.0.4-py3-none-any.whl
  • Upload date:
  • Size: 4.9 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.4-py3-none-any.whl
Algorithm Hash digest
SHA256 788b48fc202206fec6ab67ce81df24df8f5ac0718d918c0612a76dc9dbad40f5
MD5 1e1d8ddb060ae1c47ceff1af122ed542
BLAKE2b-256 389d2e339e24edf2ec2338bfef9c2587fcc668e7de632bcfa68d178b02aaef35

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