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

Uploaded Python 3

File details

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

File metadata

  • Download URL: num_word_converter-1.0.7.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.7.tar.gz
Algorithm Hash digest
SHA256 74780eaebbd4b091ebb6861911ebb4c9b23679f203c4a4211bb2157c4d1a2126
MD5 7cd4e7723b76c2914488e73b6bf1698e
BLAKE2b-256 ace8ee195599ed9544bece3cb623b67b31577c8897e8b90540865ca15f4523a5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for num_word_converter-1.0.7-py3-none-any.whl
Algorithm Hash digest
SHA256 944323a87cf1844f949f7ae7c55764683e63233c54329187fc720316bc20229f
MD5 64a4228e8dcb0def68e773a0bf48fb99
BLAKE2b-256 6119efbe78fa1714770f78cee3c74627dcfe8d84d9b1031546a079e3bf9d7fc4

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