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
|
function Int1KToText(Value: Integer; Last: Boolean): string;
const
NUM_0_19 : array[0..19] of string = (
'zéro', 'un', 'deux', 'trois', 'quatre', 'cinq', 'six', 'sept', 'huit',
'neuf', 'dix', 'onze', 'douze', 'treize', 'quatorze', 'quinze', 'seize',
'dix-sept', 'dix-huit', 'dix-neuf'
);
NUM_20_60: array[2..6] of string = (
'vingt', 'trente', 'quarante', 'cinquante', 'soixante'
);
Separateur: array[Boolean] of string = ('-', '-et-');
var
D, M: Integer;
begin
case Value of
0..19 : Result := NUM_0_19[Value];
20..69 :
begin
D := Value div 10;
M := Value mod 10;
Result := NUM_20_60[D];
if M > 0 then
Result := Result + Separateur[Value mod 10 = 1] + NUM_0_19[M];
end;
70..79 : Result := 'soixante' + Separateur[Value mod 10 = 1] + NUM_0_19[Value - 60];
80 :
begin
Result := 'quatre-vingt';
if Last then
Result := Result + 's';
end;
81..99 : Result := 'quatre-vingt-' + NUM_0_19[Value - 80];
100 : Result := 'cent';
101..199 : Result := 'cent ' + Int1KToText(Value - 100, Last);
200..999 :
begin
D := Value div 100;
M := Value mod 100;
Result := NUM_0_19[D] + '-cent';
if M = 0 then
begin
if Last then
Result := Result + 's'
end else begin
Result := Result + '-' + Int1KToText(M, Last);
end;
end
else
raise Exception.Create('Int99ToText overflow');
end;
end;
function IntToText(Value: Integer): string;
const
Units: array[0..2] of string = ('milliard', 'million', 'mille');
var
I, N, D: Integer;
begin
Result := '';
N := 1000000000;
for I := 0 to 2 do
begin
if Value >= N then
begin
if Result <> '' then
Result := Result + '-';
D := Value div N;
Value := Value - (N * D);
if (D > 1) or ((D = 1) and (I < 2)) then // "mille", "un million"
Result := Result + Int1KToText(D, I < 2) + '-';
Result := Result + Units[I];
if (D > 1) and (I < 2) then // "mille" est invariant
Result := Result + 's';
if Value = 0 then
Exit;
end;
N := N div 1000;
end;
if Result <> '' then
Result := Result + '-';
Result := Result + Int1KToText(Value, True);
end;
function DateToText(Date: TDateTime): string;
var
y, m, d: Word;
begin
DecodeDate(Date, y, m, d);
Result := IntToText(d) + '-' + FormatSettings.LongMonthNames[m] + '-' + IntToText(y);
end; |
Partager