zahlalswort
v1.0.0
Published
Convert numbers to German words (Zahlen in deutsche Wörter umwandeln)
Maintainers
Readme
zahlalswort
Convert numbers to German words.
Installation
npm install zahlalswortUsage
import { zahlAlsWort } from "zahlalswort";
zahlAlsWort(1); // "eins"
zahlAlsWort(42); // "zweiundvierzig"
zahlAlsWort(3.14); // "drei Komma eins vier"
zahlAlsWort(1000000); // "eine Million"
zahlAlsWort(-42); // "minus zweiundvierzig"API
zahlAlsWort(n: number): string
Converts a number to its German word representation.
- n - Number to convert (integers or decimals)
- Returns - German word as string, or input as string for unsupported values
Supported Range
| Min | Max | Notes |
|-----|-----|-------|
| -999,999,999,999 | 999,999,999,999 | ~1 trillion |
Fallback behavior (returns input as string):
- Numbers outside range →
"1000000000000" - Scientific notation →
"1e+21" - Infinity →
"Infinity" - NaN →
"NaN"
How it works
Integers are recursively broken down:
1234 → 1×1000 + 234
→ "ein" + "tausend" + convert(234)
→ "eintausendzweihundertvierunddreißig"Decimals use "Komma" with digits read individually:
3.14 → "drei" + "Komma" + "eins" + "vier"
→ "drei Komma eins vier"German rules applied:
- Units before tens:
vierunddreißig(4 and 30), not "dreißigvier" - Million/Milliarde are nouns:
eine Million(with space, capitalized) - Thousands concatenate:
eintausend(no space, lowercase) - Decimals:
Komma+ each digit spoken separately
Examples
| Number | Output |
|--------|--------|
| 0 | null |
| 1 | eins |
| 21 | einundzwanzig |
| 100 | einhundert |
| 1000 | eintausend |
| 1000000 | eine Million |
| 1000000000 | eine Milliarde |
| -5 | minus fünf |
| 3.14 | drei Komma eins vier |
| 0.05 | null Komma null fünf |
| -2.5 | minus zwei Komma fünf |
| 1e21 | 1e+21 (fallback) |
License
MIT
