Club Delphi  
    Paypal   FTP   CCD     Buscar   Trucos   Trabajo   Foros

Go Back   Foros Club Delphi > Principal > Varios
Register FAQ Members List Calendar Guía de estilo Search Today's Posts Mark Forums Read

Coloboración Paypal con ClubDelphi

 
 
Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 13/05/2014
Jovalca Jovalca is offline
Miembro
NULL
 
Join Date: Sep 2013
Location: Madrid - España
Posts: 30
Poder: 0
Jovalca Va por buen camino
Problema con Numero a Letra - Muestra "Un Mil" en vez de "Mil"

Hola a todos.

Ante todo, gracias por vuestro tiempo en echar un vistazo a este código.
Tengo el siguiente código, que saqué de estos mismos foros para pasar un numero a letras, tipo 1.220 a "Mil doscientos veinte".
Todo va bien con casi todos los números, he probado un montón y parece que todo va bien, pero cuando pones 1000, el texto muestra "UN MIL" en vez de "MIL".
He intentado solucionarlo pero lo único que he conseguido es que después no muestre otros números.

El codigo es el siguiente:

Código Delphi [-]
Function TForm1.CantidadEnLetra(curCantidad: Currency; MonNal: integer): String;
 var i: integer;
     Cantidad, Centavos: Currency;
     BloqueCero, NumeroBloques, Digito: Byte;
     PrimerDigito, SegundoDigito, TercerDigito: Byte;
     Resultado, Temp, strCentavos, Bloque: String;
     Unidades: Array[0..28] of String;
     Decenas: Array[0..8] of String;
     Centenas: Array[0..8] of String;
begin

Unidades[0] := 'UN'; Unidades[1] := 'DOS'; Unidades[2] := 'TRES'; Unidades[3] := 'CUATRO';
Unidades[4] := 'CINCO'; Unidades[5] := 'SEIS'; Unidades[6] := 'SIETE'; Unidades[7] := 'OCHO';
Unidades[8] := 'NUEVE'; Unidades[9] := 'DIEZ'; Unidades[10] := 'ONCE'; Unidades[11] := 'DOCE';
Unidades[12] := 'TRECE'; Unidades[13] := 'CATORCE'; Unidades[14] := 'QUINCE'; Unidades[15] := 'DIESISEIS';
Unidades[16] := 'DIESISIETE'; Unidades[17] := 'DIESIOCHO'; Unidades[18] := 'DIESINUEVE';
Unidades[19] := 'VEINTE'; Unidades[20] := 'VEINTIUNO'; Unidades[21] := 'VEINTIDOS';
Unidades[22] := 'VEINTITRES'; Unidades[23] := 'VEINTICUATRO'; Unidades[24] := 'VEINTICINCO';
Unidades[25] := 'VEINTISEIS'; Unidades[26] := 'VEINTISIETE'; Unidades[27] := 'VEINTIOCHO'; Unidades[28] := 'VEINTINUEVE';

Decenas[0] := 'DIEZ'; Decenas[1] := 'VEINTE'; Decenas[2] := 'TREINTA'; Decenas[3] := 'CUARENTA';
Decenas[4] := 'CINCUENTA'; Decenas[5] := 'SESENTA'; Decenas[6] := 'SETENTA'; Decenas[7] := 'OCHENTA'; Decenas[8] := 'NOVENTA';

Centenas[0] := 'CIENTO'; Centenas[1] := 'DOSCIENTOS'; Centenas[2] := 'TRESCIENTOS'; Centenas[3] := 'CUATROCIENTOS';
Centenas[4] := 'QUINIENTOS'; Centenas[5] := 'SEISCIENTOS'; Centenas[6] := 'SETECIENTOS'; Centenas[7] := 'OCHOCIENTOS'; Centenas[8] := 'NOVECIENTOS';

Cantidad := Trunc(curCantidad);
Centavos := (curCantidad - Cantidad) * 100;
NumeroBloques := 1;
Repeat
 PrimerDigito := 0;
 SegundoDigito := 0;
 TercerDigito := 0;
 Bloque := '';
 BloqueCero := 0;
 For i := 1 To 3 do begin
  Digito := Round(Cantidad) Mod 10;
  If Digito <> 0 Then begin
   Case i of
    1: begin
     Bloque := ' ' + Unidades[Digito - 1];
     PrimerDigito := Digito;
    end; //case 1
    2: begin
      If Digito <= 2 Then begin
       Bloque := ' ' + Unidades[(Digito * 10 + PrimerDigito - 1)];
      end Else begin
       If PrimerDigito <> 0 then
        Temp := ' Y' else Temp := '';
       Bloque := ' ' + Decenas[Digito - 1] + Temp + Bloque;
      End; //if
      SegundoDigito := Digito;
     end; //case 2
    3: begin
     If (Digito = 1) and (PrimerDigito = 0) and (SegundoDigito = 0) then
      Temp := 'CIEN' else Temp := Centenas[Digito-1];
     Bloque := ' ' + Temp + Bloque;
     TercerDigito := Digito;
     end; //case 3
    End; //case
  end Else begin
  BloqueCero := BloqueCero + 1;
  End; // If Digito <>0
  Cantidad := Int(Cantidad / 10);
  If Cantidad = 0 Then begin
   Break;
  End; // If Cantidad=0
 end; //for
 Case NumeroBloques of
  1:
   Resultado := Bloque;
  2: begin
   if BloqueCero = 3 then
    Temp := ' ' else Temp := ' MIL';
   Resultado := Bloque + Temp + Resultado;
   end; //case 2
  3: begin
   If (PrimerDigito = 1) and (SegundoDigito = 0) and (TercerDigito = 0) then
    Temp := ' MILLON' else Temp := ' MILLONES';
   Resultado := Bloque + Temp + Resultado;
   end; //case 3
 End; //case
 NumeroBloques := NumeroBloques + 1;
Until Cantidad = 0; //repeat
case MonNal of
 0: begin
 If curCantidad > 1 then
  Temp := ' CENTIMOS ###' else Temp := ' CENTIMO ###';
 CantidadEnLetra := Resultado + Temp;

 end;
 1: begin
   If curCantidad > 1 then
    Temp := ' EUROS ' else Temp := ' EURO ';
   if Centavos=0 then strCentavos := '###' else strCentavos := 'CON'+CantidadEnLetra(Centavos, 0);
   CantidadEnLetra := '###' + Resultado + Temp + strCentavos;
 end;
 2: begin
  If curCantidad > 1 then
   Temp := ' EUROS ' else Temp := ' EURO ';
   if Centavos=0 then strCentavos := '###' else strCentavos := 'CON'+CantidadEnLetra(Centavos, 0);
   CantidadEnLetra := '###' + Resultado + Temp + strCentavos;
 end;
end;

Espero podais ayudarme un poco con esto, es prácticamente lo único que me falta del programa.

Gracias de antemano por vuestra ayuda.

Un saludo.

Last edited by Casimiro Noteví : 13/05/2014 at 15:35.
Reply With Quote
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Usar TServerSocket y TClientSocket para enviar "streams" más o menos "grandes" dec Internet 9 04/08/2015 16:11
Existe algun componente "linea" y "vista miniatura"? DSK25 C++ Builder 6 09/06/2013 01:23
El programa se queda "colgado" mientras copia y luego "despierta" NeWsP OOP 5 10/03/2010 22:05
"OBJECT OR CLASS TYPE REQUIRED" en "APPLICATION EXENAME" Xavierator Varios 3 27/10/2008 09:09
Necesito llamar a métodos de clases "hija" desde su clase "padre" Flecha OOP 17 20/04/2007 00:03


All times are GMT +2. The time now is 04:49.


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