Skip to main content

A package to convert numbers to words and vice-versa

Project description

Number Word Converter

A Python library for converting numbers to words and vice versa. Supports both integers and decimal numbers.

Features

  • Convert numbers to English words
  • Convert English words to numbers
  • Support for:
    • Integers
    • Decimal numbers
    • Negative numbers
    • Large numbers (up to trillion)

Installation

For Users

pip install num-word-converter

For Developers

git clone https://github.com/lazorikv/num-word-converter.git
cd num-word-converter
pip install -e .

Usage

Number to Words

from num_word_converter import num_to_word
# Integer conversion
print(num_to_word(42)) # Output: "forty-two"
# Decimal conversion
print(num_to_word(3.14)) # Output: "three point one four"
# Negative numbers
print(num_to_word(-7)) # Output: "negative seven"
# Large numbers
print(num_to_word(1000000)) # Output: "one million"

Words to Number

from num_word_converter import word_to_num
# Integer words
print(word_to_num("forty-two")) # Output: 42
# Decimal words
print(word_to_num("three point one four")) # Output: 3.14
# Negative numbers
print(word_to_num("negative seven")) # Output: -7
# Large numbers
print(word_to_num("one million")) # Output: 1000000

Error Handling

The library includes several error types for proper error handling:

  • NonNumberInputError: Input is not a number
  • ComplexNumberInputError: Input is a complex number
  • FractionTooLongError: Fractional part is too long
  • ScaleOutOfOrderError: Scale words are in wrong order
  • NoConversionForWordError: Word cannot be converted

Limitations

  • Supports numbers up to trillion
  • Maximum 10 decimal places for floating point numbers
  • English language only

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

License

This project is licensed under the MIT License - see the LICENSE file for details.

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

num_word_converter-1.0.8.tar.gz (5.5 kB view details)

Uploaded Source

Built Distribution

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

num_word_converter-1.0.8-py3-none-any.whl (7.6 kB view details)

Uploaded Python 3

File details

Details for the file num_word_converter-1.0.8.tar.gz.

File metadata

  • Download URL: num_word_converter-1.0.8.tar.gz
  • Upload date:
  • Size: 5.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.20

File hashes

Hashes for num_word_converter-1.0.8.tar.gz
Algorithm Hash digest
SHA256 77ddc61637a3e45e609c4c261e22c89a2fe8cb0129ec832c8ccf168326a10b3d
MD5 c8b7914e9aa28c9b085551e399f96ebd
BLAKE2b-256 f6a393372eea652305f26e9286a0981ffe19d637e233aa3a55e11e017d564faa

See more details on using hashes here.

File details

Details for the file num_word_converter-1.0.8-py3-none-any.whl.

File metadata

File hashes

Hashes for num_word_converter-1.0.8-py3-none-any.whl
Algorithm Hash digest
SHA256 4100e4bbb7087bb9be4ae6ff6d6abcac3a52b674df56c03d82f5667bfa4506a6
MD5 9523156ee7d0c2e1cbd8e88d8670716b
BLAKE2b-256 4b316ed904dbd6e0ddfa8ee1b333c6e12da846044038ad1aeeca9c506b1db7c3

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