由三个函数组成。
function InTen(N: Integer): string;
var S: string;
begin
case N of
0: S := '';
1: S := ' ONE';
2: S := ' TWO';
3: S := ' THREE';
4: S := ' FOUR';
5: S := ' FIVE';
6: S := ' SIX';
7: S := ' SEVEN';
8: S := ' EIGHT';
9: S := ' NINE';
else
S := ' XX';
end;
Result := S;
end;
function InHundred(N: Integer): string;
var S: string;
begin
case N of
0: S := '';
1..9: S := InTen(N);
10: S := ' TEN';
11: S := ' ELEVEN';
12: S := ' TWELVE';
13: S := ' THIRTEEN';
14: S := ' FOURTEEN';
15: S := ' FIFTEEN';
16: S := ' SIXTEEN';
17: S := ' SEVENTEEN';
18: S := ' EIGHTEEN';
19: S := ' NINETEEN';
20..29: S := ' TWENTY' + InTen(N - 20);
30..39: S := ' THIRTY' + InTen(N - 30);
40..49: S := ' FORTY' + InTen(N - 40);
50..59: S := ' FIFTY' + InTen(N - 50);
60..69: S := ' SIXTY' + InTen(N - 60);
70..79: S := ' SEVENTY' + InTen(N - 70);
80..89: S := ' EIGHTY' + InTen(N - 80);
90..99: S := ' NINETY' + InTen(N - 90);
else S := ' XXX';
end;
Result := S;
end;
function TranslateCurrent(Num: Double): string;
var
LN: LongInt;
N1, N2, N3, N4, N5, RN: Integer;
S: string[255];
begin
S := '';
RN := Round(Abs(Num - Trunc(Num)) * 100);
(*RN := Round(Abs(Frac(Num)*100));*)
LN := Trunc(Num);
(*LN := Round(Num);*)
N1 := LN mod 100; LN := LN - N1;
N2 := Trunc(LN / 100) mod 10; LN := LN - (Trunc(N2) * 100);
N3 := Trunc(LN / 1000) mod 100; LN := LN - (Trunc(N3) * 1000);
N4 := Trunc(LN / 100000) mod 10; LN := LN - (Trunc(N4) * 100000);
N5 := Trunc(LN / 1000000) mod 100;
if N5 > 0 then S := S + InHundred(N5) + ' MILLION';
if N4 > 0 then S := S + InHundred(N4) + ' HUNDRED';
if (N4 > 0) and (N3 = 0) then S := S + ' THOUSAND';
if N3 > 0 then S := S + InHundred(N3) + ' THOUSAND';
if N2 > 0 then S := S + InHundred(N2) + ' HUNDRED';
if N1 > 0 then S := S + InHundred(N1);
if RN > 0 then S := S + ' AND CENTS ' + InHundred(RN);
Result := S;
end;
function TranslateDouble(Num: Double): string; //Dick Lee Source Code;
var
LN: LongInt;
N1, N2, N3, N4, N5, RN: Integer;
S: string[255];
begin
S := '';
RN := Round(Abs(Num - Trunc(Num)) * 100);
(*RN := Round(Abs(Frac(Num)*100));*)
LN := Trunc(Num);
(*LN := Round(Num);*)
N1 := LN mod 100; LN := LN - N1;
N2 := Trunc(LN / 100) mod 10; LN := LN - (Trunc(N2) * 100);
N3 := Trunc(LN / 1000) mod 100; LN := LN - (Trunc(N3) * 1000);
N4 := Trunc(LN / 100000) mod 10; LN := LN - (Trunc(N4) * 100000);
N5 := Trunc(LN / 1000000) mod 100;
if N5 > 0 then S := S + InHundred(N5) + ' MILLION';
if N4 > 0 then S := S + InHundred(N4) + ' HUNDRED';
if (N4 > 0) and (N3 = 0) then S := S + ' THOUSAND';
if N3 > 0 then S := S + InHundred(N3) + ' THOUSAND';
if N2 > 0 then S := S + InHundred(N2) + ' HUNDRED';
if N1 > 0 then S := S + InHundred(N1);
if RN > 0 then S := S + ' AND CENTS ' + InHundred(RN);
Result := S;
end;