[Date Prev][Date Next][Subject Prev][Subject Next][ Date Index][ Subject Index]

Translate Integers into English Words



Here's a math routine which translates any integer into a prose
string, e.g. an integer source "234" becomes the string result
"two hundred thirty-four". S/G 01 contains both input and output.
It works into the billions. Magic!
Two versions: one which simply takes a hard-coded number and translates
it (to demo the economy: the work is done in 62 bytes of code, despite
results which run into hundreds of bytes!); and a second routine which
solicits a number keyed in "live" by the user, and then translates it.
-------------
XPLeNCODE v1.9
b-gin I2$
{<}SV01,57819{>};*; Source number[cr|lf]
{<}SX02,"{<}SX03,{<}V
A{156}"+{<}IS01{>}+"{>}{>}"{>}{<}PV02{>}{<}SV01, d{>}{<}XS03,
01,01,,02{>}{<}PR@01{>}{<}EX{>}[cr|lf]
[cr|lf]
-------------[cr
|lf][cr|lf]
{<}GLA{>}[cr|lf]
{{;5int2string}} Translate e.g. "1
23" into "one hundred twenty-three"{17}Xy4|XyWin RJH 1/20/97[
cr|lf]{2};*;[cr|lf]
;*; Obtain source integer[cr|lf]
{<}LBA{>}{
<}SV01,{>}{<}LBB{>}{<}SX02,"Input integer: "+{<}IS01{>}{>}{<}
PR@02{>}{<}SX03,{<}RK{>}{>}{<}SX02,{<}VA$KC{>}{>}{<}SX02,("|"
+{<}IS02{>}+"|"){238}"|1|28|67|104|"{>}{<}IF{<}PV02{>}==0{>}{
<}LBC{>}{<}PRAbort{>}{<}EX{>}{<}EI{>}{<}IF{<}PV02{>}<0{>}{<}S
X01,{<}IS01{>}+{<}IS03{>}{>}{<}GLB{>}{<}EI{>}{<}IF{<}VA{21}01
{>}<1!{<}IS01{>}{240}"."{>}{<}GLC{>}{<}EI{>};*; S/G 01 = Sou
rce Number[cr|lf]
;*;[cr|lf]
;*; The actual routine:[cr|lf]
{<}S
X02,"{<}SX03,{<}VA{156}"+{<}IS01{>}+"{>}{>}"{>}{<}PV02{>}{<}S
V01, d{>}{<}XS03,01,01,,02{>}{<}PR@01{>}{2}[cr|lf]
-nd
XPLeNCODE
-------------
Moronic UUenCoder for XyWrite RexXPL v1.0 R.J.Holmgren 9/22/96
begin 644 INT2STR.PM
MKE-6,#$L-3WLU
M:6YT,G-T2UT:')E92(16'DT?%AY5VEN(%)*2"`Q+S(P+SDW#0H"
M.RH[#0H[*CL@3V)T86EN('-O=7)C92!I;G1E9V5R#0JN3$)!KZY35C`Q+*^N
M3$)"KZY36#`R+"));G!U="!I;G1E9V5R.B`B*ZY)4S`QKZ^N4%)`,#*OKE-8
M,#,LKE)+KZ^N4U@P,BRN5D$D2T.OKZY36#`R+"@B?"(KKDE3,#*O*R)\(BGN
M(GPQ?#(X?#8W?#$P-'PBKZY)1JY05C`RKST],*^N3$)#KZY04D%B;W)TKZY%
M6*^N14FOKDE&KE!6,#*O/#"OKE-8,#$LKDE3,#&O*ZY)4S`SKZ^N1TQ"KZY%
M2:^N24:N5D$5,#&O/#$AKDE3,#&O\"(N(J^N1TQ#KZY%2:\[*CL@(%,O1R`P
M,2`](%-O=7)C92!.=6UB97(-"CLJ.PT*.RH[(%1H92!A8W1U86P@