Skip to main content

ZahlWort2num (v.1.0.1)

🇩🇪 🇩🇪 🇩🇪 A small but useful package (due to shortage of/low quality support for lang_de) for handy conversion of German numerals (incl. ordinal numbers) written as strings to numbers.

To put it differently: It allows reverse text normalization for numbers.

This package might be a good complementary lib to https://github.com/savoirfairelinux/num2words

PyPI Project Page

https://pypi.org/project/zahlwort2num/

Web Demo

Try the interactive web demo: zahlwort2num Demo

Table of Contents

Installation

pip install zahlwort2num

Usage

Basic Usage

import zahlwort2num as w2n

Examples

# Basic cardinal numbers
w2n.convert('Zweihundertfünfundzwanzig')  # => 225

# Ordinal numbers (return as string with dot)
w2n.convert('neunte')  # => '9.'

# Negative numbers
w2n.convert('minus siebenhundert Millionen achtundsiebzig')  # => -700000078

# Complex large numbers
w2n.convert('sechshundertdreiundfünfzigtausendfünfhunderteinundzwanzig')  # => 653521

# Fractions
w2n.convert('ein und zwei')  # => 0.5
w2n.convert('drei viertel')  # => 0.75
w2n.convert('ein halb')      # => 0.5

# Decimals
w2n.convert('zwei komma fünf')  # => 2.5
w2n.convert('zehn komma eins')  # => 10.1

# Regional variants
w2n.convert('zwoa')      # => 2  (Austrian)
w2n.convert('dreissig')  # => 30 (Swiss)

Command Line Usage

Use quotes around parameters containing spaces:

zahlwort2num-convert 'eine Million siebenhunderteinundzwanzig'

Development

Setup

Install development dependencies:

python3 -m pip install -r requirements.txt

Testing

Run the test suite:

python3 -m unittest

Linting

Run the linter:

python3 -m venv venv
source ./venv/bin/activate
python3 -m pip install flake8
flake8 ./zahlwort2num/*.py --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics

Documentation

More comprehensive documentation and examples coming soon.

Features ✨

  • Large Numbers: Theoretically supports numbers from 0 up to 999 × 10^27
  • Command Line Interface: Use from terminal with zahlwort2num-convert
  • Ordinal Numbers: Supports ordinal numerals (e.g., "erste", "zweite") with inflections (suffixes like 'ste', 'ten', etc.)
    • Returns strings with dots for ordinals (e.g., '15.' instead of integer)
  • Case & Whitespace Handling: Fault-tolerant with trailing whitespaces and case variations
  • Signed Numbers: Handles negative numbers (e.g., 'minus zehn') and negative ordinals
  • Swiss German Support: Includes Swiss variants (e.g., "dreissig" vs "dreißig")
  • Austrian German Support: Includes Austrian variants (e.g., "zwoa" for 2)
  • Fault Tolerance: Handles ß → ss conversion and other common variations
  • Fraction Support: Advanced fraction conversion
    • Basic fractions (e.g., "ein und zwei" → 0.5)
    • Extended fractions (e.g., "drei viertel" → 0.75, "ein halb" → 0.5)
  • Decimal Support: Decimal number conversion (e.g., "zwei komma fünf" → 2.5)

Roadmap / Known Issues

  • Make POC, functional for all common cases
  • Ordinal number support
  • Handle exceptions and trailing whitespaces
  • Create package structure and publish to PyPI
  • Command line support
  • Support both direct and indirect forms (einhundert/hundert)
  • Simplify/refactor POC code and improve documentation
  • Add "zwo" variant support
  • Add linter and test suite
  • Swiss German variants
  • Fault tolerance (ß → ss conversion)
  • Support for scales larger than 10^60
  • Ordinal numbers with large scales (e.g., "Millionste")
  • Performance improvements (tail recursion, etc.)
  • Better error handling and validation
  • Basic fraction support
  • More comprehensive test cases
  • Extended fraction support (e.g., "drei viertel" → 0.75)
  • Decimal number support (e.g., "zwei komma fünf" → 2.5)
  • Austrian German variants

Changelog

v1.0.1 (2026-01-22)

  • Documentation improvements and changelog cleanup

v1.0.0 (2026-01-22)

  • Added extended fraction support (e.g., "drei viertel" → 0.75, "ein halb" → 0.5)
  • Added decimal number conversion (e.g., "zwei komma fünf" → 2.5)
  • Added Austrian German variants (e.g., "zwoa" for 2)
  • Enhanced test coverage and documentation

v0.4.3 (2026-01-22)

  • Enhanced testing and performance improvements
  • Bug fixes and documentation updates

v0.4.0 (2022-10-28)

  • Major feature expansion with large scale numbers and complex ordinals
  • Performance optimizations and enhanced error handling

v0.3.0 (2022-01-09)

  • Ordinal number support and Swiss German variants
  • Fault tolerance improvements

v0.2.1 (2019-05-22)

  • Command line interface and polish improvements

v0.1.9 (2019-05-08)

  • Swiss German support and ß/ss conversion
  • Enhanced regional compatibility

v0.1.6 (2019-05-05)

  • Initial release with core German number parsing
  • Basic fraction support and negative numbers

Acknowledgments

Special thanks to our contributors:

Metadata

Release files for zahlwort2num 1.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for zahlwort2num 1.0.1
File Size Uploaded
zahlwort2num-1.0.1.tar.gz 12.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for zahlwort2num 1.0.1
File Interpreter ABI Platform
zahlwort2num-1.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 23.3 kB

Release files / zahlwort2num-1.0.1.tar.gz

Download URL zahlwort2num-1.0.1.tar.gz
Size 12.1 kB
Tags Source
SHA-256 checksum
How to use checksums
5586211c8b0ad61c08d010f0ba017155686e06acce7615a30651ccb6aebcae5e
BLAKE2b-256 checksum
How to use checksums
b9429d533eb6f89ced78b636328fbe1ad9c75058c65fddd79bfa56335699fcfa
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.2

Release files / zahlwort2num-1.0.1-py3-none-any.whl

Download URL zahlwort2num-1.0.1-py3-none-any.whl
Size 11.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
80a74491d5b49b41379ede52c26971a5529279949f460f58fd32692726c7e91b
BLAKE2b-256 checksum
How to use checksums
7fdea03d3afc2f1f2d87b6fbbbb58d77f6a7d55e07afb42945e4ee43bcab7d4f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.2

Release history Release notifications | RSS feed

This release

1.0.1 This release

2 release files

1.0.0

2 release files

0.4.3

2 release files

0.4.2

2 release files

0.4.0

2 release files

0.3.0

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.9

2 release files

0.1.7

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.2

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page