RUTINA PARA CONVERTIR CIFRAS A LETRAS ( en ingles )

RUTINA PARA CONVERTIR CIFRAS A LETRAS ( en ingles )

Postby Marco Augusto » Mon Jan 29, 2007 1:44 am

Alguien tiene una rutina para convertir
cifras a letras en ingles

1250 = one thousand two hundred an fifhty

Gracias
Marco Augusto Rodriguez Manzo
FWH January 2020 Xharbour 1.2.3
MySQL 5.0.19 Fastreport

PERZO SOFT
Sistemas Personalizados
User avatar
Marco Augusto
 
Posts: 144
Joined: Wed Oct 12, 2005 1:03 pm
Location: Cuernacava, Morelos Mexico

Postby Rochinha » Mon Jan 29, 2007 1:10 pm

Amiguinho

Basta corrigir:
Code: Select all  Expand view  RUN
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+' ')
Rochinha
 
Posts: 310
Joined: Sun Jan 08, 2006 10:09 pm
Location: Brasil - Sao Paulo

Postby Marco Augusto » Mon Jan 29, 2007 2:09 pm

muchas gracias
exactamente lo que necesitaba

Saludos
Marco Augusto Rodriguez Manzo
FWH January 2020 Xharbour 1.2.3
MySQL 5.0.19 Fastreport

PERZO SOFT
Sistemas Personalizados
User avatar
Marco Augusto
 
Posts: 144
Joined: Wed Oct 12, 2005 1:03 pm
Location: Cuernacava, Morelos Mexico

JEJEJEE.

Postby leandro » Tue Jan 30, 2007 12:39 am

Amigo que pena.. de casualidad tienes la misma rutina en español...
Saludos
LEANDRO AREVALO
Bogotá (Colombia)
https://hymlyma.com
https://hymplus.com/
leandroalfonso111@gmail.com
leandroalfonso111@hotmail.com

[ Embarcadero C++ 7.60 for Win32 ] [ FiveWin 23.07 ] [ xHarbour 1.3.0 Intl. (SimpLex) (Build 20230914) ]
User avatar
leandro
 
Posts: 1688
Joined: Wed Oct 26, 2005 2:49 pm
Location: Colombia

Postby Ruben Fernandez » Tue Jan 30, 2007 2:11 am

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[u],"")
RETURN (ic+id+iu)

Saludos

Ruben Fernandez
Ruben Fernandez
 
Posts: 366
Joined: Wed Aug 30, 2006 5:25 pm
Location: Uruguay


Return to FiveWin para Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 90 guests