ordinal: Convert numbers to words in different languages.

[ bsd3, library, number, utils ] [ Propose Tags ]

A package based on Python's num2words package that converts numbers to words in different languages. It contains functions and data types to create a numbers-to-words algorithm for different languages, and converts numbers both to cardinal numbers and ordinal numbers.

[Skip to Readme]


Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees


Versions [RSS],,,,,,,,,,,,
Change log CHANGELOG.md
Dependencies base (>=4.7 && <5), containers (>=0.5), data-default-class (>=0.0.1), deepseq (>=, QuickCheck (>=2.8), regex (>=1.0), template-haskell (>=, text (>=0.1), time (>=1.0), vector (>=0.7) [details]
License BSD-3-Clause
Copyright 2020 Willem Van Onsem
Author Willem Van Onsem
Maintainer hapytexteu+gh@gmail.com
Category utils
Home page https://github.com/hapytex/ordinal#readme
Source repo head: git clone https://github.com/hapytex/ordinal
Uploaded by wvanonsem90 at 2022-06-20T15:49:34Z
Distributions NixOS:
Downloads 1779 total (28 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2022-06-20 [all 1 reports]

Readme for ordinal-

[back to package description]


Build Status of the package by GitHub actions Build Status of the package by Hackage Hackage version badge

A package to convert numbers to the words. It contains a datatype for algorithmic conversion that can convert the number for most languages. It converts numbers to its cardinal and ordinal format.

The package is based on Python's num2words package [GitHub].

The following languages are currently supported (in alphabetical order):

  1. Dutch (nl);
  2. English (en);
  3. French (fr); and
  4. German (de).


One can import the Text.Numerals module, and use the toCardinal, toOrdinal, toShortOrdinal, toTimeText and toTimeText' functions with a number-to-word algorithm that is exported by the Text.Numerals.Languages module, for example:

Prelude Text.Numerals Data.Text.IO> Data.Text.IO.putStrLn (toCardinal english 42)
Prelude Text.Numerals Data.Text.IO> Data.Text.IO.putStrLn (toOrdinal french 42)
Prelude Text.Numerals Data.Text.IO> Data.Text.IO.putStrLn (toShortOrdinal german 42)
Prelude Text.Numerals Data.Text.IO> Data.Text.IO.putStrLn (toTimeText' dutch 18 42)
twaalf minuten na half zeven 's avonds

One can also define a language algorithm themselves, for this one can look at the source code of the language modules.

Package structure

The modules are all located under Text.Numerals module. The Text.Numerals module exports the main modules.

The Text.Numerals.Class module defines classes, data types and synonyms that provide an interface to convert numbers to words.

The Text.Numerals.Algorithm module contains algorithms to make converting numbers to words more convienient. The module Text.Numerals.Algorithm.Template contains functions for template Haskell, at the moment this only contains a function to make an ordinize function.

The Text.Numerals.Prefix module contains numerical prefixes, at the moment only Latin prefixes. These are used for short scale and long scale algorithms to specify millions, billions, etc. in languages.

The Text.Numerals.Languages module exports for each implemented language its algorithm, this makes working with multiple languages more convienient. Under this module there are dedicated modules per language that do not only export the algorithm for that language, but also helper functions and constants.

ordinal is not safe Haskell

The package uses the Data.Vector module which is not safe, and therefore ordinal is not safe either.

Continuous Integration

The commits on GitHub are validated by Travis. The build will validate that the system is building, that the compiler does not generate any errors or warnings. It will also run the test-suite and will run hlint on the source code to check for improvements. Finally it will run grep on the Haskell files in the src/ directory to check for missing elements (???) and TODOs.


You can contribute by making a pull request on the GitHub repository.

You can contact the package maintainer by sending a mail to hapytexeu+gh@gmail.com.

Adding a new language

There is a src/Text/Numerals/Languages/Language.hs.template template file to include a new language. This includes a list of tasks to do in order to add the language. The test/ directory contains a test/Text/Numerals/Languages/LanguageSpec.hs.template file to test the new language. In these templates, one needs to fill in the ??? parts. One can make use of the new-language.sh script to automatically copy the templates and open the editor to add the language. In that case the name of the language is passed as first parameter.

Normally the languages are tested for all numbers in the 0-200 range, and the first hundred Fibonacci numbers greater than 200, so:


and powers of ten until 1024.

This package is dedicated to Wouter Folens (* 2019), in the hope that he will learn about transforming numbers into words.