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
| function NombreEnLettres(n : integer) : string;
Const
unite : array[1..19] of string = ('un','deux','trois','quatre','cinq','six',
'sept','huit','neuf','dix','onze','douze',
'treize','quatorze','quinze','seize',
'dix sept','dix huit','dix neuf');
dizaineF: array[2.. 9] of string = ('vingt','trente','quarante','cinquante',
'soixante','','quatre-vingt','');
dizaineB: array[2.. 9] of string = ('vingt','trente','quarante','cinquante',
'soixante','septante','octante','nonante');
coefs : array[0.. 3] of string = ('cent','mille','million','milliard');
Var
temp : String;
c, d, u : Integer;
coef : Integer;
i : Integer;
neg : boolean;
Begin
result := '';
// Cas particulier de zéro
If n = 0 then
begin
result := ' zero';
exit;
end;
// Mémorisation du signe
neg := n < 0;
If neg then n := -n;
coef:=0;
Repeat
// Récupération de l'unité du bloc de trois chiffres en cours
u:=n mod 10; n:=n div 10;
// Récupération de la dizaine du bloc de trois chiffres en cours
d:=n mod 10; n:=n div 10;
// Traitement des dizaines
temp := '';
// Passage sur la dizaine inférieure pour 10 à 19
// et pour 70-79 90-99 dans le cas de la France
If (d=1) Or ((d in [7,9])) then
begin
Dec(d);
Inc(u,10);
end;
if d > 1 then
begin
temp := ' ' + DizaineF[d];
// Ajout du cas particulier de 'et' entre la dizaine et 1
if (d < 8) and ((u = 1) or (u = 11)) then
temp := temp + ' et';
end;
// ajout du texte de l'unité
if u > 0 then temp := temp + ' ' + unite[u];
// ajout du 's' à Quatre-vingt si rien ne suit
If (result = '') and (d = 8) and (u = 0) then result := 's';
result := temp + result;
// Récupération de la centaine du bloc de trois chiffres en cours
c := n mod 10; n := n div 10; {Récupère centaine}
If c > 0 then
begin
temp := '';
if c > 1 then temp := ' ' + unite[c] + temp;
temp := temp + ' ' + coefs[0];
// Traitement du cas particulier du 's' à cent si rien ne suit
If (result = '') and (c > 1) then result := 's';
result := temp + result;
end;
// Traitement du prochain groupe de 3 chiffres
if n > 0 then
begin
Inc(coef);
I := n mod 1000;
If (i > 1) and (coef > 1) then result := 's' + result;
If i > 0 then result := ' ' + coefs[coef] + result;
// Traitement du cas particulier 'mille' ( non pas 'un mille' )
If (i = 1) and (coef = 1) then Dec(n);
end;
until n = 0;
result := Trim(result);
// Ajout du signe en cas de besoin
if neg then result := 'moins ' + result;
End; |
Partager