Club Delphi  
    Paypal   FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Principal > Varios
Registrarse FAQ Miembros Calendario Guía de estilo Temas de Hoy

Coloboración Paypal con ClubDelphi

 
 
Herramientas Buscar en Tema Desplegado
  #33  
Antiguo 27-08-2007
Avatar de BlackDaemon
BlackDaemon BlackDaemon is offline
Miembro
 
Registrado: dic 2006
Ubicación: Bolivia - Santa Cruz
Posts: 206
Poder: 20
BlackDaemon Va por buen camino
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 );
    //Componer la cifra en letra del grupo en curso.
    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.
Responder Con Cita
 



Normas de Publicación
no Puedes crear nuevos temas
no Puedes responder a temas
no Puedes adjuntar archivos
no Puedes editar tus mensajes

El código vB está habilitado
Las caritas están habilitado
Código [IMG] está habilitado
Código HTML está deshabilitado
Saltar a Foro

Temas Similares
Tema Autor Foro Respuestas Último mensaje
Utilidad para comparar dos bases de datos. avmm2004 Varios 1 16-11-2006 20:47:22
Utilidad para contar lineas de código Alexander Varios 10 18-10-2006 00:14:55
Utilidad para manejo de lista TODO ANG4L Varios 3 02-08-2006 09:36:39
Cual es la utilidad de la paleta Server Gelmin Servers 1 05-03-2004 22:20:36
utilidad del application.tag Giniromero OOP 8 17-10-2003 12:21:53


La franja horaria es GMT +2. Ahora son las 13:47:08.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi
Copyright 1996-2007 Club Delphi