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
| { ======================================================================== }
Function Convert_ch_let(chiffre: real; SM: String): string;
var tab_1_19 : array[0..19] of string[10];
tab_20_90: array[2..9] of string[20];
tab: array[1..5] of string[10];
ch_int: string[20];
ch, ch_r: string;
i, fin_I : integer;
Decimales : Real ;
Negatif : Boolean ;
Function result_1_99(ch: string): string;
begin
result_1_99 := '';
case strtoint(ch) of
0..19 : result_1_99 := tab_1_19[strtoint(ch)];
20..99 : case strtoint(ch) of
20,30,40,50,60: result_1_99 := tab_20_90[strtoint(copy(ch,1,1))];
21,31,41,51,61: result_1_99 := tab_20_90[strtoint(copy(ch,1,1))] + ' et' + tab_1_19[strtoint(copy(ch,2,1))];
80: result_1_99 := tab_20_90[strtoint(copy(ch,1,1)) ];
70..79 : result_1_99 := tab_20_90[strtoint(copy(ch,1,1)) - 1] + '-' + copy(tab_1_19[strtoint(ch) - 60],2,length(tab_1_19[strtoint(ch) - 60]) -1);
81..89 : result_1_99 := tab_20_90[strtoint(copy(ch,1,1)) ] + '-' + copy(tab_1_19[strtoint(ch) - 80],2,length(tab_1_19[strtoint(ch) - 80]) -1);
90..99 : result_1_99 := tab_20_90[strtoint(copy(ch,1,1)) - 1] + '-' + copy(tab_1_19[strtoint(ch) - 80],2,length(tab_1_19[strtoint(ch) - 80])-1 );
else
result_1_99 := tab_20_90[strtoint(copy(ch,1,1))] + '-' + copy(tab_1_19[strtoint(copy(ch,2,1))],2,length(tab_1_19[strtoint(copy(ch,2,1))]) -1);
end;
end;
end;
begin
Negatif := False ;
If (Chiffre <0 ) Then
Begin
Negatif := True ;
Chiffre := -Chiffre ;
End ;
if length(floattostr(int(chiffre))) > 15 then // s'il y a autre chose après le Billion, alors remplacer le 15 par 18
begin
messagedlg('Valeur incorrecte ',mtinformation,[mbok],0);
exit;
end;
tab_1_19[0] := '';
tab_1_19[1] := ' un'; tab_1_19[2] := ' deux'; tab_1_19[3] := ' trois';
tab_1_19[4] := ' quatre'; tab_1_19[5] := ' cinq'; tab_1_19[6] := ' six';
tab_1_19[7] := ' sept'; tab_1_19[8] := ' huit'; tab_1_19[9] := ' neuf';
tab_1_19[10] := ' dix'; tab_1_19[11] := ' onze'; tab_1_19[12] := ' douze';
tab_1_19[13] := ' treize'; tab_1_19[14] := ' quatorze'; tab_1_19[15] := ' quinze';
tab_1_19[16] := ' seize'; tab_1_19[17] := ' dix-sept'; tab_1_19[18] := ' dix-huit';
tab_1_19[19] := ' dix-neuf';
tab_20_90[2] := ' vingt'; tab_20_90[3] := ' trente'; tab_20_90[4] := ' quarante';
tab_20_90[5] := ' cinquante'; tab_20_90[6] := ' soixante';
tab_20_90[7] := ' soixante-dix'; tab_20_90[8] := ' quatre-vingt'; tab_20_90[9] := ' quatre-vingt-dix';
tab[1] := ' cent';
tab[2] := ' mille';
tab[3] := ' million';
tab[4] := ' milliard';
tab[5] := ' billion';
ch_int := floattostr(int(chiffre));
ch_r := '';
//
fin_i := length(ch_int) div 3;
if length(ch_int) > fin_i * 3 then
begin
ch := copy(ch_int,1, length(ch_int) - fin_i*3);
ch_r := result_1_99(ch);
if (strtoint(ch) = 1) and (fin_i = 1) then
ch_r := tab[fin_i + 1]
else
if length(ch_int) > 2 then
ch_r := ch_r + tab[fin_i + 1];
end;
For i := fin_i downto 1 do
begin
ch := copy(ch_int, length(ch_int) - i * 3 + 1 , 3);
case strtoint(copy(ch,1,1)) of
0: ch_r := ch_r + result_1_99(copy(ch,1,1)); // dans le cas 0, on peut remplacer result_1_99(copy(ch,1,1)) par une chaine vide. C'est à dire ch_r := ch_r + '';
1: ch_r := ch_r + tab[1]; // là aussi on peut mettre cent à la place de tab[1]
else
ch_r := ch_r + result_1_99(copy(ch,1,1)) + tab[1];
end;
if (i = 2) and (strtoint(ch) = 1) then // pour le cas de: par ex 125001489
ch_r := ch_r + copy(result_1_99(copy(ch,2,2)),3,length(result_1_99(copy(ch,2,2))) - 3 )
else
ch_r := ch_r + result_1_99(copy(ch,2,2));
if (i > 1) and (strtoint(ch) > 0) then
ch_r := ch_r + tab[i];
end;
SM := Trim(SM) ;
if SM <> '' then
begin
ch_r := Uppercase(copy(ch_r,2,1)) + copy(ch_r,3,length(ch_r) - 2) + ' ' + SM;
if frac(chiffre) > 0 then
ch_r := ch_r + ' et ' + copy(floattostr(frac(chiffre) + 1.005 ),3,2) + ' cts.';
// le 1.005 pour obtenir le bon resultat, enlever le et essayer avec les montants suivants: par ex 15,20 ou 147,50
end
Else
Begin
ch_r := Uppercase(copy(ch_r,2,1)) + copy(ch_r,3,length(ch_r) - 2) ;
if frac(chiffre) > 0 then
Begin
Decimales := Round(frac(chiffre)*100) ;
ch_r := ch_r + ' virgule ' + LowerCase(Convert_ch_let(Decimales, '')) ;
End ;
End ;
If Negatif Then ch_r := 'Moins '+ LowerCase(ch_r) ;
Convert_ch_let := ch_r;
End; |
Partager