summaryrefslogtreecommitdiff
path: root/info/examples/tip/ntotext.tip
blob: cd1f26a4d039806f6efb720e53a297ee8558e653 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
% This macro source file is from the four volume series
% "TeX in Practice" by Stephan von Bechtolsheim, published
% 1993 by Springer-Verlag, New York.
% Copyright 1993 Stephan von Bechtolsheim.
% No warranty or liability is assumed.
% This macro may be copied freely if no fees other than
% media cost or shipping charges are charged and as long
% as this copyright and the following source code itself
% is not changed. Please see the series for further information.
%
% Version: 1.0
% Date: May 1, 1993
%
%
% This source code is documented in 3.3.16, p. I-63.
% Original source in file "reg1.TEX", starting line 1835.
\wlog{L: "ntotext.tip" ["reg1.TEX," l. 1835, p. I-63]}%
% This file DOES belong to format "texip."
\InputD{imodn.tip}
\catcode`\@ = 11
\def\@OneDigitNumberText #1#2{%
    \ifcase #2\relax
        \ifnum #1=0
        \else
            zero%
        \fi
        \or
        one\or
        two\or
        three\or
        four\or
        five\or
        six\or
        seven\or
        eight\or
        nine% 
    \else
        \errmessage{\string\@OneDigitNumberText: number
            \number#2 out of range.}%
    \fi
}
\newcount\@NumberToConvert
\newcount\@NumberToConvertTwo
\newcount\@NumberToConvertAndFlag
\def\NumberToText #1{% 
    \@NumberToConvert = #1\relax    
    \ifnum\@NumberToConvert < 0
        minus
        \@NumberToConvert = -\@NumberToConvert
    \fi
    \CheckRange{\@NumberToConvert}{0}{999999}%
        {\string\NumberToText: numbers >= 1.000.000
            not handled.}%
    \@NumberToConvertAndFlag = 0
    \ifnum\@NumberToConvert > 999
        \@NumberToConvertTwo = \@NumberToConvert
        \divide\@NumberToConvert by 1000
        \@NumberToText
        \space thousand and
        \IModN{\@NumberToConvertTwo}{1000}{\@NumberToConvert}%
    \fi 
    \CheckRange{\@NumberToConvert}{0}{999}%
        {\string\NumberToText: internal error 1}%
    \@NumberToText
}
\newcount\@NumberToTextTmp
\def\@NumberToText{%
    \ifnum\@NumberToConvert > 99
        \ValueOfDecimalPosition{\@NumberToConvert}{2}% 
            {\@NumberToTextTmp}%
        \@OneDigitNumberText{1}{\@NumberToTextTmp}% 
        \space hundred and
        \IModN{\@NumberToConvert}{100}{\@NumberToConvert}%
    \fi
    \ValueOfDecimalPosition{\@NumberToConvert}{1}%
        {\@NumberToTextTmp}%
    \ifnum\@NumberToTextTmp > 1
        \ifcase\@NumberToTextTmp
                \errmessage{\string\@NumberToText:
                    internal error 1.}%
            \or
                \errmessage{\string\@NumberToText:
                    internal error 2.}%
            \or
            twenty\or
            thirty\or
            forty\or
            fifty\or
            sixty\or
            seventy\or
            eighty\or
            ninety%
        \else
            \errmessage{\string\@NumberToText:
                internal error 4.}%
        \fi
        \IModN{\@NumberToConvert}{10}{\@NumberToTextTmp}%
            \@OneDigitNumberText{0}{\@NumberToTextTmp}%
    \else
        \ifnum\@NumberToTextTmp = 1
            \advance\@NumberToConvert by -10
            \ifcase\@NumberToConvert
                ten\or
                eleven\or
                twelve\or
                thirteen\or
                fourteen\or
                fifteen\or
                sixteen\or
                seventeen\or
                eighteen\or
                nineteen%
            \fi
        \else
            \@OneDigitNumberText{1}{\@NumberToConvert}%
        \fi
    \fi
}
\catcode`\@ = 12