numspell:   Spelling Numbers as English
1 Introduction
2 Interface
write-number-as-english
write-number-as-short-scale-english
write-number-as-long-scale-english
number->english
number->short-scale-english
number->long-scale-english
3 History
4 Legal
2:1

numspell: Spelling Numbers as English🔗ℹ

Neil Van Dyke

 (require numspell) package: numspell

1 Introduction🔗ℹ

The numspell package provides the ability to “spell” Racket numbers in English. This could in theory be useful for writing numbers on banking checks and other legal documents, but lawyers say we should totally disclaim that it is suitable for those purposes.
Most rational numbers 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"
The number names supported by numspell 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"
This package is currently for Racket, but was originally written to require only R5RS Scheme, SRFI-6 (string ports), and SRFI-11 (let-values). Note that some numbers, such as very large and very small non-integers printed by some Scheme implementations in exponential notation, are not supported.

2 Interface🔗ℹ

The public interface consists of a few procedures.

procedure

(write-number-as-english num port)  void

  num : number?
  port : output-port?
(write-number-as-short-scale-english num    
  port)  void
  num : number?
  port : output-port?
(write-number-as-long-scale-english num    
  port)  void
  num : number?
  port : output-port?
Spell number num to output port port. If num cannot be spelt, an error is signaled.

procedure

(number->english num)  string?

  num : number?
(number->short-scale-english num)  string?
  num : number?
(number->long-scale-english num)  string?
  num : number?
Yield a string that spells number num. If num cannot be spelt,an error is signaled.

3 History🔗ℹ

4 Legal🔗ℹ

Copyright 2006, 2009, 2011, 2016 Neil Van Dyke. This program is Free Software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but without any warranty; without even the implied warranty of merchantability or fitness for a particular purpose. See http://www.gnu.org/licenses/ for details. For other licenses and consulting, please contact the author.