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/username/num-word-converter.git
cd num-word-converter
pip install -e ".[dev]"

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: num_word_converter-1.0.6.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.6.tar.gz
Algorithm Hash digest
SHA256 0ef362af825bc3b1529d64232fcdbb4d464f60ccc7178888c47d129abc33715b
MD5 c9c9fa436a38b88e4023fa909c97991b
BLAKE2b-256 79a43a79b82713b00be95db9b74c61e5e4dd4ea4aa58c154e2235bedae96ac00

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for num_word_converter-1.0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 4c7c64e73c41f319108ee2483e9abe458881fab0c76b93f67462a4a266fc55da
MD5 30c3b07b7430fa1aca210504e27c185a
BLAKE2b-256 053d9348603b441d622ffdc1e09d2785f6d234962387b9c64720acd23900e386

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