A comprehensive Python library for parsing and converting numbers between numeric, word, and ordinal formats.
Project description
numbr
numbr is a Python library designed for parsing and converting numbers written in English. It simplifies working with numbers by converting between spelled-out forms, ordinal forms, and numeric representations.
Key Features
- Convert spelled-out cardinal numbers into integers (e.g.,
"one hundred twenty-three"→123). - Convert integers into their spelled-out English words (e.g.,
123→"one hundred twenty-three"). - Convert ordinal words to numeric ordinals (e.g.,
"twenty-first"→"21st"or21). - Extract numeric values from text strings.
- Handle negative numbers, hyphenated numbers, and large numbers (up to quintillions).
Installation
Install numbr using pip:
pip install numbr
Usage Examples
Convert Words to Integer
import numbr
print(numbr.wordsToInt("one thousand two hundred thirty-four"))
# Output: 1234
Convert Integer to Words
print(numbr.intToWords(5678))
# Output: "five thousand six hundred seventy-eight"
Convert Ordinal Words to Numeric Form
print(numbr.ordinalWordsToInt("forty-second"))
# Output: "42nd"
print(numbr.ordinalWordsToInt("forty-second", to_num=True))
# Output: 42
Extract Numeric Values from Strings
print(numbr.extractNumericValue("I have twenty apples and 13 oranges."))
# Output: 20
Terminology
- Cardinal Numbers: Represent quantity (e.g., "one", "twenty-five", "1,234").
- Ordinal Numbers: Represent position or order (e.g., "first", "twenty-first", "3rd").
- Ordinal Suffix: Letters added to numbers indicating position ("st", "nd", "rd", "th").
License
This project is licensed under the MIT License. See the LICENSE file for details.
Contributing
Contributions are welcome! Feel free to open issues or submit pull requests to improve numbr.
Contact
For questions or feedback, please open an issue on the project's GitHub repository.
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 numbr-1.0.0.tar.gz.
File metadata
- Download URL: numbr-1.0.0.tar.gz
- Upload date:
- Size: 16.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.8.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2bb3923e28ff6314744485bfe1ddf4798a2a0316167a071b571d332826b0af86
|
|
| MD5 |
7a0891d2a8fbd6e3bc2f9fbd6317409a
|
|
| BLAKE2b-256 |
8be67a37a8648c3b5f0ca0b596cf7370289621fc47b5f64d526fc8d40ff40c54
|
File details
Details for the file numbr-1.0.0-py3-none-any.whl.
File metadata
- Download URL: numbr-1.0.0-py3-none-any.whl
- Upload date:
- Size: 15.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.8.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
04b6927e9d23f38732ac1b1f4e7a9750e5530e89b5bf8b48a6ac8b891e07b16c
|
|
| MD5 |
d70187fb5d2c46aa3827cae2ec879e02
|
|
| BLAKE2b-256 |
62f2e66d90939035111555fd813c30c218c1127fb9f6ac5c86e84b3446872867
|