Num2Words

0.5.14 · active · verified Thu Apr 09

Num2Words is a Python library designed to convert numerical values into their word representations across multiple languages. It supports various output formats, including cardinal numbers (e.g., 'forty-two'), ordinal numbers (e.g., 'forty-second'), years, and currency representations with appropriate localization. The library is currently active, with the latest stable version being 0.5.14, and receives regular updates, primarily focusing on adding new language support and fixing existing localizations.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to import the `num2words` function and use it for various conversion types, including cardinal, ordinal, ordinal number, and currency formats, as well as specifying a target language.

from num2words import num2words

# Basic cardinal conversion (default)
print(num2words(42)) # forty-two

# Ordinal conversion
print(num2words(42, to='ordinal')) # forty-second

# Ordinal number conversion
print(num2words(42, to='ordinal_num')) # 42nd

# Currency conversion (defaults to 'dollar' or 'euro' based on language)
print(num2words(1234.56, to='currency', currency='USD')) # one thousand, two hundred and thirty-four dollars, fifty-six cents

# French language conversion
print(num2words(42, lang='fr')) # quarante-deux

view raw JSON →