Aquí una función que convierte cifras numéricas a texto..
(lo saque de de una lista de correo)
Aunque no es exactamente inservible, por que hay componente que hacen lo mismo (Creo)
Código Delphi
[-] function Letras( nNumero: Extended ): string;
const
Y = 'y ' ;
F = 'as ' ;
M = 'os ' ;
MIL = 'mil ' ;
MILLON = 'millón ' ;
MILLONES = 'millones ';
BILLON = 'billón ' ;
BILLONES = 'billones ';
var
cEnLetra : string;
cNumStr : string;
cUnidad : string;
cDecena : string;
cCentena : string;
cDecStr : string;
cAux : string;
nGrupo : Integer;
aGrupos : Array[1..5] of string;
function Decena( n1,n2: integer ): string;
begin
result := '';
if ( n1 = 2 ) and ( n2 = 1 ) then
if ( cUnidad = '0' ) then
result := 'diez '
else
result := '';
if n1 = 2 then
case n2 of
2: result := 'once ';
3: result := 'doce ';
4: result := 'trece ';
5: result := 'catorce ';
6: result := 'quince ';
7: result := 'dieciseis ';
8: result := 'diecisiete ';
9: result := 'dieciocho ';
10: result := 'diecinueve ';
end;
if ( n1 = 3 ) then
if ( cUnidad = '0' ) then
result := 'veinte '
else
result := 'veinti';
if ( n1 = 4 ) then
if ( cUnidad <> '0' ) then
result := 'treinta ' + Y
else
result := 'treinta ';
if ( n1 = 5 ) then
if ( cUnidad <> '0' ) then
result := 'cuarenta ' + Y
else
result := 'cuarenta ';
if ( n1 = 6 ) then
if ( cUnidad <> '0' ) then
result := 'cincuenta ' + Y
else
result := 'cincuenta ';
if ( n1 = 7 ) then
if ( cUnidad <> '0' ) then
result := 'sesenta ' + Y
else
result := 'sesenta ';
if ( n1 = 8 ) then
if ( cUnidad <> '0' ) then
result := 'setenta ' + Y
else
result := 'setenta ';
if ( n1 = 9 ) then
if ( cUnidad <> '0' ) then
result := 'ochenta ' + Y
else
result := 'ochenta ';
if ( n1 = 10 ) then
if ( cUnidad <> '0' ) then
result := 'noventa ' + Y
else
result := 'noventa ';
end;
function Unidad ( n : integer ): string;
var
sNumero : Array [3..10] of string;
begin
result := '';
sNumero[3] := 'dos ' ; sNumero[4] := 'tres '; sNumero[5] := 'cuatro ';
sNumero[6] := 'cinco '; sNumero[7] := 'seis '; sNumero[8] := 'siete ';
sNumero[9] := 'ocho ' ; sNumero[10] := 'nueve ';
case n of
1: if ( nNumero = 0 ) and ( nGrupo = 1 ) then
result := 'cero';
2: if ( cDecena = '1' ) then
result := Decena( 2, StrToInt( cUnidad ) + 1 )
else if ( aGrupos[nGrupo] = '001' ) and ( (nGrupo = 2 ) or ( nGrupo = 4 )) then
result := ''
else if ( nGrupo = 2 ) or ( nGrupo = 3 ) then
result := 'un '
else
result := 'uno ';
3..10: if ( cDecena = '1' ) then
result := Decena( 2, StrToInt( cUnidad ) + 1 )
else
result := sNumero[n];
end;
end;
function Centena ( n1 : integer ): string;
begin
result := '';
case n1 of
1: result := '';
2: if ( cDecena + cUnidad ) = '00' then
result := 'cien '
else
result := 'ciento ';
3: result := 'doscientos ';
4: result := 'trescientos ';
5: result := 'cuatrocientos ';
6: result := 'quinientos ';
7: result := 'seiscientos ';
8: result := 'setecientos ';
9: result := 'ochocientos ';
10: result := 'novecientos ';
end;
end;
function Conector( n1 : integer ): string;
begin
result := '';
case n1 of
1: result := '';
2,4: if aGrupos[n1] > '000' then
result := MIL;
3: if ( aGrupos[3] > '000' ) or ( aGrupos[4] > '000' ) then
if aGrupos[3] = '001' then
result := MILLON
else
result := MILLONES;
5: if ( aGrupos[5] > '000' ) then
if aGrupos[5] = '001' then
result := BILLON
else
result := BILLONES;
end;
end;
begin
cAux := Format( '%15.2f',[nNumero] );
cNumStr := Trim(Format( '%15.15d',[Trunc(nNumero)] ));
if nNumero - Trunc( nNumero ) = 0 then
cDecStr := ''
else
cDecStr := 'con '+Copy( cAux,Length(cAux)-1,2)+'/100';
for nGrupo := 1 to 5 do
aGrupos[5-nGrupo+1] := Copy( cNumStr, (nGrupo - 1) * 3 + 1, 3);
cEnLetra := '';
for nGrupo := 5 downto 1 do
begin
cUnidad := Copy( aGrupos[nGrupo],Length(aGrupos[nGrupo]),1);
cDecena := Copy( aGrupos[nGrupo], 2, 1 );
cCentena := Copy( aGrupos[nGrupo], 1, 1 );
cEnLetra := cEnLetra + Centena ( StrToInt( cCentena ) + 1 ) +
Decena ( StrToInt( cDecena ) + 1, 1 ) +
Unidad ( StrToInt( cUnidad ) + 1 ) +
Conector( nGrupo );
end;
if Copy( cEnLetra, 1, 3 ) = 'mil' then
result := 'un ' + cEnLetra + cDecStr
else
result := cEnLetra + cDecStr;
end;
saludos!
PD si no esta permitido este tipo de códigos quitadlo, solo quería colaborar.