RUTINA PARA CONVERTIR CIFRAS A LETRAS ( en ingles )

Post Reply
Marco Augusto
Posts: 122
Joined: Wed Oct 12, 2005 1:03 pm
Location: Cuernacava, Morelos Mexico

RUTINA PARA CONVERTIR CIFRAS A LETRAS ( en ingles )

Post by Marco Augusto »

Alguien tiene una rutina para convertir
cifras a letras en ingles

1250 = one thousand two hundred an fifhty

Gracias
Marco Augusto Rodriguez Manzo
fwh 2020 Xharbour 1.2.3
MySQL 5.0.19 Fastreport

PERZO SOFT
Sistemas Personalizados
Rochinha
Posts: 309
Joined: Sun Jan 08, 2006 10:09 pm
Location: Brasil - Sao Paulo
Contact:

Post by Rochinha »

Amiguinho

Basta corrigir:

Code: Select all

FUNCTION EXTENSO( PVALOR )
LOCAL TSTR   := STRZERO(PVALOR,18,2)
LOCAL ACIFRA := {{'Trilhon','Trilhons'},;
                 {'Bilhon' ,'Bilhons'},;
                 {'Milhon' ,'Milhons'},;
                 {'Thousand'    ,'Thousand'},;
                 {'   '    ,'   '},;
                 {'Cent','Cents'}}
LOCAL TX
LOCAL TEXTENSO := ' '
LOCAL TSUBS    := ' '
LOCAL TCENTAVOS:= VAL(SUBSTR(TSTR,17))
IF (PVALOR>0)
   IF (TCENTAVOS>0)
      TEXTENSO:=EXTCEM(STRZERO(TCENTAVOS,3))+;
      ACIFRA[6][IIF(TCENTAVOS=1,1,2)]
   ENDIF
   IF (INT(PVALOR)>0)
      TEXTENSO:=IIF(INT(PVALOR)=1,'Real','Reals')+IIF(TCENTAVOS>0,' and ','')+TEXTENSO
   ENDIF
   FOR TX := 5 TO 1 STEP -1
       IF (VAL(TSUBS:=SUBSTR(TSTR,(TX*3)-2,3))>0)
          TEXTENSO:=EXTCEM(TSUBS)+ACIFRA[TX][IIF(VAL(TSUBS)=1,1,2)]+' '+TEXTENSO
       ENDIF
   NEXT TX
ENDIF
RETURN(STRIPDOUBLE(TEXTENSO,' '))

FUNCTION EXTCEM(PCEM)
LOCAL AVAL := {VAL(SUBSTR(PCEM,1,1)),;
               VAL(SUBSTR(PCEM,2,1)),;
               VAL(SUBSTR(PCEM,3,1))}
LOCAL TTAM,TEXT := ''
LOCAL ACENT := { 'one hundred','two hundred','Three hundred','Four hundred','Five hundred','Six hundred','Seven hundred','Eight hundred','Nine hundred'}
LOCAL AVINT := { 'Eleven','Twelve','Thirteen','Fourteen','Fifiteen','Sixteen','Seventeen','Eighteen','Nineteen' }
LOCAL ADEZ  := { 'Ten','Twenty','Thirty','Forty','Fifty','Sixty','Seventy','Eighty','Ninety' }
LOCAL AUNIT := { 'One','Two','Three','Four','Five','Six','Seven','Eight','Nine' }
IF (VAL(PCEM)>0)
   IF (VAL(PCEM)==100)
      TEXT := 'Hundred '
   ELSE
      IF (AVAL[1]>0)
         TEXT := ACENT[AVAL[1]]+IIF((AVAL[2]+AVAL[3]>0),' and ',' ')
      ENDIF
      IF (AVAL[2]=1).AND.(AVAL[3]>0)
         TEXT := TEXT + ' '+AVINT[AVAL[3]]
      ELSE
         IF (AVAL[2]>0)
            TEXT := TEXT+' '+ADEZ[AVAL[2]]+IIF(AVAL[3]>0,' and ','')
         ENDIF
         TEXT := TEXT+IIF(AVAL[3]>0,' '+AUNIT[AVAL[3]],' ')
      ENDIF
   ENDIF
ENDIF
RETURN(TEXT := TEXT+' ')
Marco Augusto
Posts: 122
Joined: Wed Oct 12, 2005 1:03 pm
Location: Cuernacava, Morelos Mexico

Post by Marco Augusto »

muchas gracias
exactamente lo que necesitaba

Saludos
Marco Augusto Rodriguez Manzo
fwh 2020 Xharbour 1.2.3
MySQL 5.0.19 Fastreport

PERZO SOFT
Sistemas Personalizados
User avatar
leandro
Posts: 958
Joined: Wed Oct 26, 2005 2:49 pm
Location: Colombia
Contact:

JEJEJEE.

Post by leandro »

Amigo que pena.. de casualidad tienes la misma rutina en español...
Saludos
LEANDRO ALFONSO
SISTEMAS LYMA - BASE
Bogotá (Colombia)
[ FWH 19.09 ] [ xHarbour 1.2.3 Intl. (SimpLex) (Build 20190613) ] [ Embarcadero C++ 7.30 for Win32 ]
Ruben Fernandez
Posts: 366
Joined: Wed Aug 30, 2006 5:25 pm
Location: Uruguay

Post by Ruben Fernandez »

Leandro:

Espero te sirva.

FUNCTION ImporteConLetra(Importe,cMon)
LOCAL Centavos, Millones, Miles, ImpLet:=""
Centavos:=Right(TRAN(Importe,"999999999999.99"),2)
if importe < 0 ; importe := importe *-1;endif
Importe:=Importe+.005
Millones:=INT(Importe/1000000)
IF Millones>0
Importe:=Importe-(Millones*1000000)
ImpLet:=GeneraImporte(Millones)
ImpLet:=ImpLet+IF(Importe=0,"millones de ",;
IF(Millones=1,"millón ","millones "))
ENDIF
Miles:=INT(Importe/1000)
IF Miles>0
Importe:=Importe-(Miles*1000)
ImpLet:=ImpLet+GeneraImporte(Miles)+"mil "
ENDIF
ImpLet:=ImpLet+GeneraImporte(Importe)
ImpLet:=IF(cMon="D",ImpLet+"dólares "+"con "+centavos+"/100 u.s.",;
ImpLet+"pesos " +"con " +centavos+"/100 m.n." )
RETURN (ImpLet)

STATIC FUNCTION GeneraImporte(Importe)
LOCAL ic, id, iu, c, d, u, re, a_Cen, a_Dec, a_Uni
ic:=id:=iu:=""
c:=d:=u:=re:=0
a_Uni:={"un ","dos ","tres ","cuatro ","cinco ","seis ","siete ","ocho ",;
"nueve ","diez ","once ","doce ","trece ","catorce ","quince " ,;
"dieciseis ","diecisiete ","dieciocho ","diecinueve ","veinte " ,;
"veintiun ","veintidos ","veintitres ","veinticuatro ","veinticinco ",;
"veintiseis ","veintisiete ","veintiocho ","veintinueve "}
a_Dec:={"diez ","veinte ","treinta ","cuarenta ","cincuenta ","sesenta ",;
"setenta ","ochenta ","noventa "}
a_Cen:={"ciento ","doscientos ","trescientos ","cuatrocientos ","quinientos ",;
"seiscientos ","setecientos ","ochocientos ","novecientos "}

c:=INT(Importe/100)
re:=Importe-(c*100)
ic:=IF((c=1 .AND. re=0),"cien ",IF(c<>0,a_Cen[c],""))
d:=INT(re/10)
re:=IF(d>2,(re-(d*10)),re)
id:=IF(d>2,a_Dec[d],"")
id:=IF((d>2 .AND. re>=1),id+"y ",id)
u:=INT(re)
iu:=IF(u>0 .AND. u<30,a_Uni,"")
RETURN (ic+id+iu)

Saludos

Ruben Fernandez
Post Reply