Delphi - Convertir Valores a Letras..con centavos

 
Vista:
sin imagen de perfil

Convertir Valores a Letras..con centavos

Publicado por sam123 (1 intervención) el 20/07/2015 04:40:20
Necesito alguien me ayude, en este mismo codigo me lo edite para que muestre los centavos, actualmente no me esta mostrando los centavos, y asi no me sirve, asi como esta funciona, la unica diferencia es que no me muestra los centavos.. espero alguien lo edite y me lo envie por correo..

saludos

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
CREATE PROCEDURE SP_NUMLETRAS (
  PVALOR NUMERIC(15, 2)
) RETURNS (
  RVALOR VARCHAR(10000)
) AS declare variable VVLR_ENTERO integer;
declare variable VVALOR numeric(15,2);
declare variable VLETRAS varchar(10000);
declare variable VELETRAS2 varchar(10000);
declare variable VELETRAS3 varchar(10000);
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(:vvalor - 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);
   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 / 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) into VELETRAS2;
    VLETRAS = 'UN BILLON  ' || VELETRAS2;
   END
   else
    BEGIN
    vvlr_entero = TRUNC(VVALOR / 1000000000000);
    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
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
sin imagen de perfil
Val: 65
Oro
Ha mantenido su posición en Delphi (en relación al último mes)
Gráfica de Delphi

Convertir Valores a Letras..con centavos

Publicado por E.T. (1244 intervenciones) el 20/07/2015 18:06:46
Podrias simplemente agregar la resta de tu valor entero (que ya lo estas obteniendo) menos tu valor de entrada, agregandolo al final de tu procedimiento.

algo asi:
1
RVALOR = VLETRAS || ' ' || cast(PVALOR - vvlr_entero as varchar(2)) || '/100'

que base de datos estás usando?

EDIT: no lo he probado, pero parece ser que te va a agregar centavos cada vez que la ejecutas, así que tendrias que agregar un parámetro en el que indiques si deseas los centavos, explico:
cuando ejecutes tu procedimiento lo ejecutarias con el parametro indicando que quieres los centavos, pero cuando ejecutas el procedimiento desde dentro de él mismo lo ejecutas sin pedir los centavos, así al finalizar todo el ciclo de ejecuciones, solo al último se agregarian los centavos
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar