[déplacé BAR -> DELPHI] convertir un nombre decimal en lettre

Résolu
tojosource Messages postés 3 Date d'inscription vendredi 20 mars 2009 Statut Membre Dernière intervention 15 mars 2010 - 8 févr. 2010 à 06:28
dubois77 Messages postés 675 Date d'inscription jeudi 17 avril 2008 Statut Membre Dernière intervention 19 février 2019 - 12 févr. 2010 à 13:53
bonjour tout le monde ,

J'ai un fonction qui est ceci:


//-------------------------------Ma fonction------------
function TF_Main.Convert_ch_let(chiffre: Double; SM: string): string;
var tab_1_19 : array[0..19] of string[10];
tab_20_90: array[2..9] of string[20];
tab_01_90: array[1..9] of string[20];
tab: array[1..5] of string[10];
ch_int: string[20];
ch, ch_r: string;
i, fin_I : integer;
vraimbl : double ;
traimbl : string ;
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
vraimbl := 0 ;
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[1] := ' vingt';
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_01_90[1] := ' zéro';
tab_01_90[2] := ' vingt'; tab_01_90[3] := ' trente'; tab_01_90[4] := ' quarante';
tab_01_90[5] := ' cinquante'; tab_01_90[6] := ' soixante';
tab_01_90[7] := ' soixante-dix'; tab_01_90[8] := ' quatre-vingt'; tab_01_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;

if SM <> '' then
begin
if SM = 'Ar' Then SM := 'Ariary' ;
ch_r := Uppercase(copy(ch_r,2,1)) + copy(ch_r,3,length(ch_r) - 2);
if frac(chiffre) > 0 then
//Convert_ch_let(frac(chiffre) + 1.005, '')
//ch_r := 'Ar ' + ch_r + 'et ' + copy(floattostr(frac(chiffre) + 1.005 ),3,2) ;
//ch_r := 'Ar ' + ch_r + ', et ' + Convert_ch_let(strToFloat(copy(floattostr(frac(chiffre) + 1.005 ),3,2)), '') ;
vraimbl := strToFloat(copy(floattostr(frac(chiffre) + 1.005 ),3,2)) ;
traimbl := Convert_ch_let(vraimbl, '') ;
ch_r := ch_r + ' ' + SM + ' ' + traimbl ;
// le 1.005 pour obtenir le bon resultat, enlever le et essayer avec les montants suivants: par ex 15,20 ou 147,50
end;

Convert_ch_let := ch_r;
//--------------------------Ma fonction ---------------

je veux que ça sort qlq chose commeça:


si j'ecrit 100,05 dollard il me donne cent dollard zéro cinq mais il aval le zéro et il me donne cent dollard cinq. si qlq un a une réponse qu'il m'aide Merci.

3 réponses

cs_akzo Messages postés 133 Date d'inscription dimanche 23 juin 2002 Statut Membre Dernière intervention 3 janvier 2015 3
8 févr. 2010 à 20:58
Salut,
Il y en a deja quelque un par ici qui sont pas mal s'ils peuvent t'aider un peu.
http://www.vbfrance.com/codes/CONVERTIR-CHIFFRES-LETTRES_42584.aspx
Salutation
3
Caribensila Messages postés 2527 Date d'inscription jeudi 15 janvier 2004 Statut Membre Dernière intervention 16 octobre 2019 18
9 févr. 2010 à 00:16
Salut,

Quand des soit-disant programmeurs ne se donnent pas la peine de regarder ce qui a déjà été fait et ce qui s'est déjà passé avant eux, je ne m'étonne plus des crises financières...
0
dubois77 Messages postés 675 Date d'inscription jeudi 17 avril 2008 Statut Membre Dernière intervention 19 février 2019 14
12 févr. 2010 à 13:53
Tu es dur Caribensila, car le lien proposé (à bon escient) est en visual basic donc les delphistes ne sont pas forcément attiré par ce langage et ne vont pas forcément chercher de ce coté là
Un peu d'indulgence !


Dubois77
0
Rejoignez-nous