numspell.scm: Spelling Numbers as English in Scheme

The numspell.scm library provides the ability to "spell" Scheme numbers in English. This is useful for writing numbers on banking checks and other legal documents, as well as for speech generation.

Most rational numbers in Scheme are presently supported. For example:

(number->english 123456)
⇒ "one hundred twenty-three thousand four hundred fifty-six"
(number->english (/ 4 -6))
⇒ "negative two over three"
(number->english (exact->inexact (/ 4 -6)))
⇒ "negative zero point six six six six six six" ; approx.

The number names supported by numspell.scm are taken from a version of the Wikipedia "Names of large numbers" article. Both short and long scales are supported, through different procedures, with short scale being the default. For example:

(number->english             (expt 10 15))
⇒ "one quadrillion"
(number->short-scale-english (expt 10 15))
⇒ "one quadrillion"
(number->long-scale-english  (expt 10 15))
⇒ "one thousand billion"

Note: Some numbers, such as very large and very small non-integers printed by some Scheme implementations in exponential notation, are not supported by the current version of numspell.scm.

numspell.scm requires R5RS, SRFI-6 (string ports), and SRFI-11 (let-values).

See documentation for more info...

To be added to the moderated scheme-announce email list, ask neil@neilvandyke.org .

The current version of numspell.scm is 0.3 (2006-05-07).

You can download file numspell.scm, Scheme source code.

You can download file numspell.html, documentation in HTML format.

You can download file numspell.pdf, documentation in PDF format.

You can download file numspell.plt, a packaging for PLT Scheme.

Site © 1994-2008 Neil Van Dyke   neil@neilvandyke.org    XHTML 1.0 Strict  CSS2    Legal