2 # Author: Noah Friedman <friedman@prep.ai.mit.edu>
4 # Last modified: 1993-04-01
7 # Conversion to bash v2 syntax done by Chet Ramey
13 # Usage: number [number]
15 # Converts decimal integers to english notation. Spaces and commas are
16 # optional. Numbers 67 digits and larger will overflow this script.
18 # E.g: number 99,000,000,000,000,454
19 # => ninety-nine quadrillion four hundred fifty-four
35 echo "number: invalid character in argument." 1>&2
39 echo "number: fractions not supported (yet)." 1>&2
46 eval set - "`echo ${1+\"$@\"} | sed -n -e '
47 s/[, ]//g;s/^00*/0/g;s/\(.\)\(.\)\(.\)$/\"\1 \2 \3\"/;
50 s/\([^\" ][^\" ]*\)\([^\" ]\)\([^\" ]\)\([^\" ]\)/\1\"\2 \3 \4\"/g;
53 /^[0-9][0-9][0-9]/s/\([^\" ]\)\([^\" ]\)\([^\" ]\)/\"\1 \2 \3\"/;
54 /^[0-9][0-9]/s/\([^\" ]\)\([^\" ]\)/\"\1 \2\"/;
55 /^[0-9]/s/^\([^\" ][^\" ]*\)/\"\1\"/g;s/\"\"/\" \"/g;p;'`"
57 while test $# -ne 0 ; do
63 3 ) d3=$1 d2=$2 d1=$3 ;;
65 echo "d3=\"${d3}\" d2=\"${d2}\" d1=\"${d1}\""`
67 val1
='' val2
='' val3
=''
83 '2' ) val2
='twenty' ;;
84 '3' ) val2
='thirty' ;;
88 '7' ) val2
='seventy' ;;
89 '8' ) val2
='eighty' ;;
90 '9' ) val2
='ninety' ;;
100 '3') val1
='thirteen' ;;
101 '4') val1
='fourteen' ;;
102 '5') val1
='fifteen' ;;
103 '6') val1
='sixteen' ;;
104 '7') val1
='seventeen' ;;
105 '8') val1
='eighteen' ;;
106 '9') val1
='nineteen' ;;
111 if test ".${val2}" != '.' && test ".${d1}" != '.0' ; then
115 '0') val2
="${val2} " ;;
129 if test ".${val3}" != '.' ; then
130 result
="${result}${val3} hundred "
133 if test ".${val2}" != '.' ; then
134 result
="${result}${val2}"
137 if test ".${val1}" != '.' ; then
138 result
="${result}${val1} "
141 if test ".${d1}${d2}${d3}" != '.000' ; then
144 2 ) result
="${result}thousand " ;;
145 3 ) result
="${result}million " ;;
146 4 ) result
="${result}billion " ;;
147 5 ) result
="${result}trillion " ;;
148 6 ) result
="${result}quadrillion " ;;
149 7 ) result
="${result}quintillion " ;;
150 8 ) result
="${result}sextillion " ;;
151 9 ) result
="${result}septillion " ;;
152 10 ) result
="${result}octillion " ;;
153 11 ) result
="${result}nonillion " ;;
154 12 ) result
="${result}decillion " ;;
155 13 ) result
="${result}undecillion " ;;
156 14 ) result
="${result}duodecillion " ;;
157 15 ) result
="${result}tredecillion " ;;
158 16 ) result
="${result}quattuordecillion " ;;
159 17 ) result
="${result}quindecillion " ;;
160 18 ) result
="${result}sexdecillion " ;;
161 19 ) result
="${result}septendecillion " ;;
162 20 ) result
="${result}octodecillion " ;;
163 21 ) result
="${result}novemdecillion " ;;
164 22 ) result
="${result}vigintillion " ;;
166 echo "Error: number too large (66 digits max)." 1>&2
185 # number.bash ends here