Club Delphi  
    FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Principal > SQL
Registrarse FAQ Miembros Calendario Guía de estilo Buscar Temas de Hoy Marcar Foros Como Leídos

Respuesta
 
Herramientas Buscar en Tema Desplegado
  #1  
Antiguo 16-07-2015
sam123 sam123 is offline
Registrado
NULL
 
Registrado: jul 2015
Posts: 6
Poder: 0
sam123 Va por buen camino
Convertir Números a Letras con Centavos

Quien me ayuda, tengo este procedimiento para convertir numeros a Letras, al momento de convertir a letras no convierte los centavos, les agradecere
Código SQL [-]
begin

   if (PVALOR IS NULL) then

   EXIT;

    VVALOR= abs(PVALOR);

   if (vvalor = 0) THEN  VLETRAS =  'CERO';

   else if (VVALOR = 1) then   VLETRAS = 'UN';

   else if (VVALOR = 2) then   VLETRAS = 'DOS';

   else if (VVALOR = 3) then   VLETRAS = 'TRES';

   else if (VVALOR = 4) then   VLETRAS = 'CUATRO';

   else if (VVALOR = 5) then   VLETRAS = 'CINCO';

   else if (VVALOR = 6) then   VLETRAS = 'SEIS';

   else if (VVALOR = 7) then   VLETRAS = 'SIETE';

   else if (VVALOR = 8) then   VLETRAS = 'OCHO';

   else if (VVALOR = 9) then   VLETRAS = 'NUEVE';

   else if (VVALOR = 10) then   VLETRAS = 'DIEZ';

   else if (VVALOR = 11) then   VLETRAS = 'ONCE';

   else if (VVALOR = 12) then   VLETRAS = 'DOCE';

   else if (VVALOR = 13) then   VLETRAS = 'TRECE';

   else if (VVALOR = 14) then   VLETRAS = 'CATORCE';

   else if (VVALOR = 15) then   VLETRAS = 'QUINCE';

   else if (VVALOR < 20) then

   begin

    select rvalor  from sp_numletras(:vvalor - 10) into VELETRAS2;

    VLETRAS = 'DIECI' || VELETRAS2;

   end

   else if (VVALOR = 20) then   VLETRAS = 'VEINTE';

   else if (VVALOR < 30) then

   begin

    select rvalor  from sp_numletras(:pvalor - 20) into VELETRAS2;

    VLETRAS = 'VEINTI' || VELETRAS2;

   end

   else if (VVALOR = 30) then   VLETRAS = 'TREINTA';

   else if (VVALOR = 40) then   VLETRAS = 'CUARENTA';

   else if (VVALOR = 50) then   VLETRAS = 'CINCUENTA';

   else if (VVALOR = 60) then   VLETRAS = 'SESENTA';

   else if (VVALOR = 70) then   VLETRAS = 'SETENTA';

   else if (VVALOR = 80) then   VLETRAS = 'OCHENTA';

   else if (VVALOR = 90) then   VLETRAS = 'NOVENTA';

   else if (VVALOR < 100) then

   begin

   vvlr_entero = TRUNC(VVALOR / 10.2);

   select rvalor  from sp_numletras(:VVLR_ENTERO * 10) into VELETRAS2;

   select rvalor  from sp_numletras(MOD(:VVALOR,10)) into VELETRAS3;

   VLETRAS = VELETRAS2 || ' Y ' || VELETRAS3;

   END

   else if (VVALOR = 100) then   VLETRAS = 'CIEN';

   else if (VVALOR < 200) then

   begin

    select rvalor  from sp_numletras(:vvalor - 100) into VELETRAS2;

    VLETRAS = 'CIENTO  ' || VELETRAS2;

   END

   ELSE  if ((VVALOR = 200) or (VVALOR = 300) or (VVALOR = 400) or (VVALOR = 600) or (VVALOR = 800)) THEN

   begin

   vvlr_entero = TRUNC(VVALOR || 00/100);

    select rvalor  from sp_numletras(:VVLR_ENTERO) into VELETRAS2;

    VLETRAS = VELETRAS2 || ' ' || 'CIENTOS';

   END

   else if (VVALOR = 500) then   VLETRAS = 'QUINIENTOS';

   else if (VVALOR = 700) then   VLETRAS = 'SETECIENTOS';

   else if (VVALOR = 900) then   VLETRAS = 'NOVECIENTOS';

   else if (VVALOR < 1000) then

   begin

   vvlr_entero = TRUNC(VVALOR / 100);

   select rvalor  from sp_numletras(:VVLR_ENTERO * 100) into VELETRAS2;

   select rvalor  from sp_numletras(MOD(:VVALOR,100)) into VELETRAS3;

   VLETRAS = :VELETRAS2 || ' ' || :VELETRAS3;

   END

   else if (VVALOR = 1000) then   VLETRAS = 'MIL';

   else if (VVALOR < 2000) then

   begin

    select rvalor  from sp_numletras(MOD(:vvalor , 1000)) into VELETRAS2;

    VLETRAS = 'MIL  ' || VELETRAS2;

   END

   else if (VVALOR < 1000000) then

   begin

   vvlr_entero = TRUNC(VVALOR / 1000);

   select rvalor  from sp_numletras(:VVLR_ENTERO) into VELETRAS2;

   select rvalor  from sp_numletras(MOD(:VVALOR,1000)) into VELETRAS3;

   VLETRAS = VELETRAS2 || ' MIL ' ||  VELETRAS3;

   END

   else if (VVALOR = 1000000) then   VLETRAS = 'UN MILLON';

   else if (VVALOR < 2000000) then

   begin

    select rvalor  from sp_numletras(MOD(:vvalor , 1000000)) into VELETRAS2;

    VLETRAS = 'UN MILLON  ' || VELETRAS2;

   END

   else if (VVALOR < 1000000000000) then

   begin

   vvlr_entero = TRUNC(VVALOR / 1000000);

   select rvalor  from sp_numletras(:VVLR_ENTERO) into VELETRAS2;

   select rvalor  from sp_numletras(:VVALOR - :VVLR_ENTERO * 1000000) into VELETRAS3;

   VLETRAS = :VELETRAS2 || ' MILLONES ' ||  :VELETRAS3;

   END

   else if (VVALOR = 1000000000000) then   VLETRAS = 'UN BILLON';

   else if (VVALOR < 2000000000000) then

   begin

    vvlr_entero = TRUNC(VVALOR / 1000000000000);

    select rvalor  from sp_numletras(:vvalor - :VVLR_ENTERO * 1000000000000.00) into VELETRAS2;

    VLETRAS = 'UN BILLON  ' || VELETRAS2;

   END

   else

    BEGIN

    vvlr_entero = TRUNC(VVALOR / 1000000000000,00);

    select rvalor  from sp_numletras(:VVLR_ENTERO) into VELETRAS2;

    select rvalor  from sp_numletras(:VVALOR - :VVLR_ENTERO * 1000000000000) into VELETRAS3;

    VLETRAS = VELETRAS2 || ' BILLONES ' ||  VELETRAS3;

    END

   RVALOR = VLETRAS;

  suspend;

end

Última edición por ecfisa fecha: 16-07-2015 a las 15:45:13. Razón: Etiquetas [SQL] [/SQL]
Responder Con Cita
  #2  
Antiguo 16-07-2015
Avatar de escafandra
[escafandra] escafandra is offline
Miembro Premium
 
Registrado: nov 2007
Posts: 2.195
Poder: 20
escafandra Tiene un aura espectacularescafandra Tiene un aura espectacular
Puedes pasarte por aquí. Hace unos días, como parte de un reto, desarrollamos tres códigos distintos de escaso tamaño para realizar la conversión de números a texto.


Saludos.
Responder Con Cita
  #3  
Antiguo 16-07-2015
Avatar de ecfisa
ecfisa ecfisa is offline
Moderador
 
Registrado: dic 2005
Ubicación: Tres Arroyos, Argentina
Posts: 10.508
Poder: 36
ecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to behold
Hola sam123, bienvenido a Club Delphi

Algunos enlaces mas:
Saludos
__________________
Daniel Didriksen

Guía de estilo - Uso de las etiquetas - La otra guía de estilo ....

Última edición por ecfisa fecha: 16-07-2015 a las 04:44:16.
Responder Con Cita
  #4  
Antiguo 16-07-2015
Avatar de nlsgarcia
[nlsgarcia] nlsgarcia is offline
Miembro Premium
 
Registrado: feb 2007
Ubicación: Caracas, Venezuela
Posts: 2.206
Poder: 21
nlsgarcia Tiene un aura espectacularnlsgarcia Tiene un aura espectacular
sam123,

¡Bienvenido al Club Delphi!

Nelson.
Responder Con Cita
  #5  
Antiguo 16-07-2015
Avatar de nlsgarcia
[nlsgarcia] nlsgarcia is offline
Miembro Premium
 
Registrado: feb 2007
Ubicación: Caracas, Venezuela
Posts: 2.206
Poder: 21
nlsgarcia Tiene un aura espectacularnlsgarcia Tiene un aura espectacular
sam123,

Cita:
Empezado por sam123
...Convertir Números a Letras con Centavos...


Revisa este código:
Código Delphi [-]
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Edit1: TEdit;
    Memo1: TMemo;
    Button2: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

// Convierte números a letras de forma recursiva
function NumbersToLetters(Number: Double) : String;
const
  Digit: array[1..9] of String = ('Uno', 'Dos', 'Tres',
                                  'Cuatro', 'Cinco', 'Seis',
                                  'Siete', 'Ocho', 'Nueve');

  Numeral: array[11..19] of String = ('Once', 'Doce', 'Trece',
                                      'Catorce', 'Quince', 'Diez y Seis',
                                      'Diez y Siete', 'Diez y Ocho', 'Diez y Nueve');

  Tenths: array[1..9] of String = ('Diez', 'Veinte', 'Trienta',
                                   'Cuarenta', 'Cincuenta', 'Sesenta',
                                   'Setenta', 'Ochenta', 'Noventa');

  Hundreds : array[1..9] of String = ('Cien ', 'Docientos ', 'Trecientos ',
                                      'Cuatrocientos ', 'Quinientos ', 'Seicientos ',
                                      'Setecientos ', 'Ochocientos ', 'Novecientos ');

  Min = 1;
  Max = 4294967295;

  function RecursiveNumber(N: LongWord) : String;
  begin

    case N of

      1..9:
      begin
         Result := Digit[N];
      end;

      11..19:
      begin
         Result := Numeral[N]
      end;

      10,20..99:
      begin
         if (N Mod 10) = 0 then
            Result := Tenths[N div 10] + RecursiveNumber(N mod 10)
         else
            Result := Tenths[N div 10] + ' y '  + RecursiveNumber(N mod 10);
      end;

      100..999:
      begin
        if (N = 100) or (N >= 200) then Result := Hundreds[N div 100] + RecursiveNumber(N mod 100);
        if (N > 100) and (N < 200) then Result := 'Ciento ' + RecursiveNumber(N mod 100);
      end;

      1000..999999:
      begin
         if (Number >= 1000) and (Number < 2000) then
            Result := 'Un Mil ' + RecursiveNumber(N mod 1000)
         else
            Result := RecursiveNumber(N div 1000) + ' Mil ' + RecursiveNumber(N mod 1000);
      end;

      1000000..999999999:
      begin
         if (Number >= 1000000) and (Number < 2000000) then
            Result := 'Un Millon ' + RecursiveNumber(N mod 1000000)
         else
            Result := RecursiveNumber(N div 1000000) + ' Millones ' + RecursiveNumber(N mod 1000000);
      end;

      1000000000..4294967295:
      begin
         if (Number >= 1000000000) and (Number < 2000000000) then
            Result := 'Un Millardo ' + RecursiveNumber(N mod 1000000)
         else
            Result := RecursiveNumber(N div 1000000000) + ' Millardos ' + RecursiveNumber(N mod 1000000000);
      end;

    end;

  end;

begin
  if (Number >= Min) and (Number <= Max) then
     begin
        Result := RecursiveNumber(Trunc(Number));
        Result := Result +  ' con ' + FormatFloat('00',Frac(Number) * 100) + '/100';
     end
  else
     Result := '-1';
end;

procedure TForm1.Button1Click(Sender: TObject);
var
   Number : Double;
begin
   if TryStrToFloat(Edit1.Text,Number) then
      Memo1.Text := NumbersToLetters(Number)
   else
      MessageDlg('Error en formato de Número',mtError,[mbOK],0);
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
   Edit1.Text := EmptyStr;
   Memo1.Clear;   
end;

end.
El código anterior en Delphi 7 sobre Windows 7 Professional x32, Convierte números a letras por medio de una función recursiva, como se muestra en la siguiente imagen:



Espero sea útil

Nelson.

Última edición por nlsgarcia fecha: 16-07-2015 a las 21:52:32.
Responder Con Cita
  #6  
Antiguo 17-07-2015
sam123 sam123 is offline
Registrado
NULL
 
Registrado: jul 2015
Posts: 6
Poder: 0
sam123 Va por buen camino
Editar este Codigo

Alguien me puede editar este codigo que me muestre los centavos al momento que lo convierta a Letras..

saludos
Responder Con Cita
  #7  
Antiguo 17-07-2015
Avatar de nlsgarcia
[nlsgarcia] nlsgarcia is offline
Miembro Premium
 
Registrado: feb 2007
Ubicación: Caracas, Venezuela
Posts: 2.206
Poder: 21
nlsgarcia Tiene un aura espectacularnlsgarcia Tiene un aura espectacular
sam123,

Cita:
Empezado por sam123
...este código que me muestre los centavos al momento que lo convierta a Letras...


Revisa este código:
Código Delphi [-]
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Edit1: TEdit;
    Memo1: TMemo;
    Button2: TButton;
    GroupBox1: TGroupBox;
    RadioButton1: TRadioButton;
    RadioButton2: TRadioButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

// Convierte números a letras de forma recursiva
function NumbersToLetters(Number: Double; Centime : Boolean) : String;
const
  Digit: array[1..9] of String = ('Uno', 'Dos', 'Tres',
                                  'Cuatro', 'Cinco', 'Seis',
                                  'Siete', 'Ocho', 'Nueve');

  Numeral: array[11..19] of String = ('Once', 'Doce', 'Trece',
                                      'Catorce', 'Quince', 'Diez y Seis',
                                      'Diez y Siete', 'Diez y Ocho', 'Diez y Nueve');

  Tenths: array[1..9] of String = ('Diez', 'Veinte', 'Trienta',
                                   'Cuarenta', 'Cincuenta', 'Sesenta',
                                   'Setenta', 'Ochenta', 'Noventa');

  Hundreds : array[1..9] of String = ('Cien ', 'Docientos ', 'Trecientos ',
                                      'Cuatrocientos ', 'Quinientos ', 'Seicientos ',
                                      'Setecientos ', 'Ochocientos ', 'Novecientos ');

  Min = 1;
  Max = 4294967295;

  function RecursiveNumber(N: LongWord): String;
  begin

    case N of

      1..9:
      begin
         Result := Digit[N];
      end;

      11..19:
      begin
         Result := Numeral[N]
      end;

      10,20..99:
      begin
         if (N Mod 10) = 0 then
            Result := Tenths[N div 10] + RecursiveNumber(N mod 10)
         else
            Result := Tenths[N div 10] + ' y '  + RecursiveNumber(N mod 10);
      end;

      100..999:
      begin
        if (N = 100) or (N >= 200) then Result := Hundreds[N div 100] + RecursiveNumber(N mod 100);
        if (N > 100) and (N < 200) then Result := 'Ciento ' + RecursiveNumber(N mod 100);
      end;

      1000..999999:
      begin
         if (Number >= 1000) and (Number < 2000) then
            Result := 'Un Mil ' + RecursiveNumber(N mod 1000)
         else
            Result := RecursiveNumber(N div 1000) + ' Mil ' + RecursiveNumber(N mod 1000);
      end;

      1000000..999999999:
      begin
         if (Number >= 1000000) and (Number < 2000000) then
            Result := 'Un Millon ' + RecursiveNumber(N mod 1000000)
         else
            Result := RecursiveNumber(N div 1000000) + ' Millones ' + RecursiveNumber(N mod 1000000);
      end;

      1000000000..4294967295:
      begin
         if (Number >= 1000000000) and (Number < 2000000000) then
            Result := 'Un Millardo ' + RecursiveNumber(N mod 1000000)
         else
            Result := RecursiveNumber(N div 1000000000) + ' Millardos ' + RecursiveNumber(N mod 1000000000);
      end;

    end;

  end;

var
   F : String;

begin
  if (Number >= Min) and (Number <= Max) then
     begin
        Result := RecursiveNumber(Trunc(Number));
        F := FormatFloat('00',Frac(Number) * 100);
        if Centime then
           Result := Result +  ' con ' + RecursiveNumber(StrToInt(F)) + ' Centimos'
        else
           Result := Result +  ' con ' + F + '/100';
     end
  else
     Result := '-1';
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
   RadioButton1.Checked := True;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
   Number : Double;
begin
   if TryStrToFloat(Edit1.Text,Number) then
   begin
      if RadioButton1.Checked then
         Memo1.Text := NumbersToLetters(Number,True);

      if RadioButton2.Checked then
         Memo1.Text := NumbersToLetters(Number,False)
   end
   else
      MessageDlg('Error en formato de Número',mtError,[mbOK],0);
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
   Edit1.Text := EmptyStr;
   Memo1.Clear;
   RadioButton1.Checked := True;
   Edit1.SetFocus;
end;

end.
El código anterior en Delphi 7 sobre Windows 7 Professional x32 es una variación del presentado en el Msg #5, el cual permite : Convertir números a letras por medio de una función recursiva y escoger si los céntimos son visualizados como letras o fracción, como se muestra en la siguiente imagen:



El código del ejemplo esta disponible en : NumbersToLetters.rar

Espero sea útil

Nelson.
Responder Con Cita
  #8  
Antiguo 17-07-2015
sam123 sam123 is offline
Registrado
NULL
 
Registrado: jul 2015
Posts: 6
Poder: 0
sam123 Va por buen camino
Muchas gracias por los aporte

Talvez no me explique bien, o no logro comprender el cosdigo que me enviastes, que esta excelente pero lo miro funciona coo una aplicacion por separado, yo lo necesito para hacer una factura de ventas, y que automaticamente me lo convierta, si estoy equivocado, sobre el usuo de este codigo me dices como ussarlo, y pegarlo al modulo e facturacion

saludos
Responder Con Cita
  #9  
Antiguo 17-07-2015
Avatar de nlsgarcia
[nlsgarcia] nlsgarcia is offline
Miembro Premium
 
Registrado: feb 2007
Ubicación: Caracas, Venezuela
Posts: 2.206
Poder: 21
nlsgarcia Tiene un aura espectacularnlsgarcia Tiene un aura espectacular
sam123,

Cita:
Empezado por sam123
...no logro comprender el código que me enviastes...lo necesito para hacer una factura de ventas...


Te comento:

1- El código del Msg #7 sirve como ejemplo del uso de la función NumbersToLetters.

2- Para usar la función NumbersToLetters en cualquier programa, solo debes incluirla en el mismo por medio de una unidad o DLL y ejecutarla con los parámetros requeridos.

Revisa esta información:
Espero sea útil

Nelson.
Responder Con Cita
Respuesta


Herramientas Buscar en Tema
Buscar en Tema:

Búsqueda Avanzada
Desplegado

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
Convertir números en letras c748a Varios 14 10-04-2015 21:52:18
Convertir Numeros en Letras hondaalberto Varios 1 13-06-2012 17:10:29
convertir Numeros en Letras Rofocale Varios 5 27-04-2010 05:55:54
Dudas al convertir numero en letra y centavos rufo Varios 14 27-11-2009 23:26:26
Cómo convertir números a letras JKABARCA Varios 1 11-08-2008 01:20:41


La franja horaria es GMT +2. Ahora son las 11:56:57.


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