Convert numbers to Nepali-style words and formatting
Project description
A comprehensive Python library for converting numbers to Nepali-style currency words with support for both English transliteration and Nepali Unicode (Devanagari script). Perfect for financial applications, educational tools, and any system requiring Nepali number formatting.
✨ Features
- 🔢 Number to Words Conversion: Convert integers and floats to Nepali-style number words
- 🇳🇵 Dual Language Support: English transliteration and authentic Nepali Unicode (Devanagari)
- 💰 Currency Support: Automatic rupees and paise handling for decimal amounts
- 📊 Nepali Number Formatting: Format numbers with traditional Nepali comma placement (10,00,000)
- 📦 Compact Representation: Human-readable format (1.2 lakhs, 4.5 crores)
- ⚡ CLI Tools: Complete command-line interface suite
- 🛡️ Robust Error Handling: Comprehensive input validation and clear error messages
- ➖ Negative Number Support: Handles negative values seamlessly
🚀 Quick Start
Installation
pip install nepali-num2word
Basic Usage
from nepali_num2word import convert_to_words, format_number, compact_number
# Convert to words (English)
print(convert_to_words(123456))
# Output: one lakh twenty-three thousand four hundred fifty-six
# Convert to words (Nepali)
print(convert_to_words(123456, lang='np'))
# Output: एक लाख तेइस हजार चार सय छप्पन्न
# Format with Nepali-style commas
print(format_number(1234567))
# Output: 12,34,567
# Format with Nepali Unicode digits
print(format_number(1234567, lang='np'))
# Output: १२,३४,५६७
# Compact representation
print(compact_number(1234567))
# Output: 12.3 lakhs
📖 Documentation
API Reference
convert_to_words(number, lang='en')
Convert numbers to words in Nepali numbering system.
Parameters:
number(int | float | str): Number to convert (supports negative numbers)lang(str): Language code -'en'for English,'np'for Nepali Unicode
Returns: str - Number converted to words
Examples:
convert_to_words(120000) # "one lakh twenty thousand"
convert_to_words(34000000) # "three crore forty lakh"
convert_to_words(123.45) # "one hundred twenty-three rupees and forty-five paise"
convert_to_words(-123) # "-one hundred twenty-three"
# Nepali Unicode
convert_to_words(120000, lang='np') # "एक लाख बीस हजार"
convert_to_words(123.45, lang='np') # "एक सय तेइस रुपैयाँ र पैँतालीस पैसा"
format_number(number, lang='en')
Format numbers with Nepali-style comma separation.
Parameters:
number(int | float): Number to formatlang(str): Language code -'en'for English digits,'np'for Nepali Unicode digits
Returns: str - Formatted number string
Examples:
format_number(1000000) # "10,00,000"
format_number(120000) # "1,20,000"
format_number(34000000) # "3,40,00,000"
# Nepali Unicode digits
format_number(1000000, lang='np') # "१०,००,०००"
format_number(120000, lang='np') # "१,२०,०००"
format_number(123.45, lang='np') # "१२३.४५"
compact_number(number, lang='en')
Convert numbers to compact, human-readable format.
Parameters:
number(int | float | str): Number to convertlang(str): Language code -'en'for English,'np'for Nepali Unicode
Returns: str - Compact number representation
Examples:
compact_number(999) # "999"
compact_number(1500) # "1.5 thousand"
compact_number(100000) # "1 lakh"
compact_number(4200000) # "42 lakhs"
compact_number(42000000) # "4.2 crores"
# Nepali Unicode
compact_number(4200000, lang='np') # "४२ लाख"
compact_number(42000000, lang='np') # "४.२ करोड"
Command Line Interface
The package includes three CLI commands:
nepaliword - Convert numbers to words
nepaliword 120000
# Output: one lakh twenty thousand
nepaliword 123.45 --lang np
# Output: एक सय तेइस रुपैयाँ र पैंतालीस पैसा
nepaliformat - Format with Nepali-style commas
nepaliformat 1000000
# Output: 10,00,000
nepaliformat 1000000 --lang np
# Output: १०,००,०००
nepalicompact - Compact number representation
nepalicompact 4200000
# Output: 42 lakhs
nepalicompact 42000000 --lang np
# Output: ४.२ करोड
🛡️ Error Handling
The library provides comprehensive error handling with clear, actionable error messages:
Supported Input Types
- ✅ Integers:
123,-456 - ✅ Floats:
123.45,-67.89 - ✅ Numeric strings:
"123","123.45","-456"
Error Examples
# Type errors
convert_to_words(None) # TypeError: Number cannot be None
convert_to_words(True) # TypeError: Boolean values are not supported
convert_to_words([]) # TypeError: Unsupported type: list
# Value errors
convert_to_words("") # ValueError: Empty string is not a valid number
convert_to_words("hello") # ValueError: 'hello' is not a valid number
convert_to_words(1000000000) # ValueError: Number too large (max: 999,999,999)
🎯 Use Cases
- Financial Applications: Convert amounts to words for checks, invoices, and receipts
- Educational Software: Teaching Nepali number systems and currency
- Government Systems: Official documents requiring Nepali number representation
- Banking Software: Amount verification and display in Nepali format
- E-commerce: Price display in traditional Nepali numbering
🔧 Development
Local Development Setup
# Clone the repository
git clone https://github.com/kushal1o1/nepali-num2word.git
cd nepali-num2word
# Install in development mode
pip install -e .
# Run tests
python -m pytest tests/
# Test CLI locally
python cli/main.py 120000 --lang np
python cli/format_main.py 1000000
python cli/compact_main.py 4200000
Project Structure
nepali-num2word/
├── nepali_num2word/
│ ├── __init__.py
│ └── core.py
├── cli/
│ ├── main.py
│ ├── format_main.py
│ └── compact_main.py
├── static/
│ └── image/
│ └── nepali-num2word.png
├── tests/
│ ├── __init__.py
│ ├── conftest.py
│ ├── test_core.py
│ └── test_cli.py
├── README.md
├── CONTRIBUTING.md
├── LICENSE
├── setup.py
├── pyproject.toml
├── requirements.txt
└── requirements-dev.txt
🤝 Contributing
We welcome contributions! Please see our Contributing Guide for details on how to get started.
Quick Contribution Steps
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Make your changes
- Add tests for new functionality
- Ensure all tests pass (
python -m pytest) - Commit your changes (
git commit -m 'Add amazing feature') - Push to your branch (
git push origin feature/amazing-feature) - Open a Pull Request
📋 Roadmap
- Integer to words in Nepali format
- Decimal (paise) support
- Nepali Unicode output
- CLI tool support
- Nepali-style number formatting
- Compact number representation
- Comprehensive error handling
- Reverse conversion (Nepali words → number)
📊 Performance
The library is optimized for performance with minimal dependencies:
- Zero external dependencies for core functionality
- Efficient string building algorithms
- Comprehensive input validation
- Memory-efficient processing
🌍 Language Support
| Feature | English | Nepali Unicode |
|---|---|---|
| Number to Words | ✅ | ✅ |
| Currency (Rupees/Paise) | ✅ | ✅ |
| Negative Numbers | ✅ | ✅ |
| Compact Format | ✅ | ✅ |
| CLI Support | ✅ | ✅ |
📄 License
This project is licensed under the MIT License - see the LICENSE file for details.
🙏 Acknowledgments
- Built with ❤️ for the Nepali community
- Inspired by the need for proper Nepali number formatting in software applications
- Thanks to all contributors who help improve this library
📞 Support
- Issues: GitHub Issues
- Discussions: GitHub Discussions
- Email: Contact maintainer
Made in Nepal | Created by Kushal1o1
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file nepali_num2word-0.2.3.tar.gz.
File metadata
- Download URL: nepali_num2word-0.2.3.tar.gz
- Upload date:
- Size: 20.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2b59a534594230c2e40ccdca0a5e069c7198091e06f7d3fcb741c8d594cf28fb
|
|
| MD5 |
cb4d505e67cffdc81cadc55ecf62419a
|
|
| BLAKE2b-256 |
ead8e67029d730339d1cce60b55f8227df575e494542b369467855be6ca3a0e0
|
Provenance
The following attestation bundles were made for nepali_num2word-0.2.3.tar.gz:
Publisher:
publish.yml on kushal1o1/nepali-num2word
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
nepali_num2word-0.2.3.tar.gz -
Subject digest:
2b59a534594230c2e40ccdca0a5e069c7198091e06f7d3fcb741c8d594cf28fb - Sigstore transparency entry: 413149620
- Sigstore integration time:
-
Permalink:
kushal1o1/nepali-num2word@42b29f0dc5479e2af79f3f9bfc747c4ca3d55e98 -
Branch / Tag:
refs/tags/v0.2.3 - Owner: https://github.com/kushal1o1
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@42b29f0dc5479e2af79f3f9bfc747c4ca3d55e98 -
Trigger Event:
release
-
Statement type:
File details
Details for the file nepali_num2word-0.2.3-py3-none-any.whl.
File metadata
- Download URL: nepali_num2word-0.2.3-py3-none-any.whl
- Upload date:
- Size: 14.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9c3e62af6ecd8a5f5780ecb934571ce53cc7a6b5fc82288495261f5341719295
|
|
| MD5 |
f0f47577d8ff7f247f188cea1446d10e
|
|
| BLAKE2b-256 |
769551954dd702536c83eb70250ab6460447f360870b1dd7157b2fbaa11e0b4e
|
Provenance
The following attestation bundles were made for nepali_num2word-0.2.3-py3-none-any.whl:
Publisher:
publish.yml on kushal1o1/nepali-num2word
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
nepali_num2word-0.2.3-py3-none-any.whl -
Subject digest:
9c3e62af6ecd8a5f5780ecb934571ce53cc7a6b5fc82288495261f5341719295 - Sigstore transparency entry: 413149635
- Sigstore integration time:
-
Permalink:
kushal1o1/nepali-num2word@42b29f0dc5479e2af79f3f9bfc747c4ca3d55e98 -
Branch / Tag:
refs/tags/v0.2.3 - Owner: https://github.com/kushal1o1
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@42b29f0dc5479e2af79f3f9bfc747c4ca3d55e98 -
Trigger Event:
release
-
Statement type: