Alguien tiene una rutina para convertir
cifras a letras en ingles
1250 = one thousand two hundred an fifhty
Gracias
RUTINA PARA CONVERTIR CIFRAS A LETRAS ( en ingles )
- Marco Augusto
- Posts: 145
- Joined: Wed Oct 12, 2005 1:03 pm
- Location: Cuernacava, Morelos Mexico
- Has thanked: 1 time
RUTINA PARA CONVERTIR CIFRAS A LETRAS ( en ingles )
Marco Augusto Rodriguez Manzo
FWH January 2020 Xharbour 1.2.3
MySQL 5.0.19 Fastreport
PERZO SOFT
Sistemas Personalizados
FWH January 2020 Xharbour 1.2.3
MySQL 5.0.19 Fastreport
PERZO SOFT
Sistemas Personalizados
Amiguinho
Basta corrigir:
Basta corrigir:
Code: Select all | Expand
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: 145
- Joined: Wed Oct 12, 2005 1:03 pm
- Location: Cuernacava, Morelos Mexico
- Has thanked: 1 time
- leandro
- Posts: 1744
- Joined: Wed Oct 26, 2005 2:49 pm
- Location: Colombia
- Has thanked: 34 times
- Been thanked: 10 times
- Contact:
JEJEJEE.
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
[ Turbo Incremental Link64 6.98 Embarcadero 7.70 ] [ FiveWin 24.09 ] [ xHarbour 64 bits) ]
LEANDRO AREVALO
Bogotá (Colombia)
https://hymlyma.com
https://hymplus.com/
leandroalfonso111@gmail.com
leandroalfonso111@hotmail.com
[ Turbo Incremental Link64 6.98 Embarcadero 7.70 ] [ FiveWin 24.09 ] [ xHarbour 64 bits) ]
-
- Posts: 366
- Joined: Wed Aug 30, 2006 5:25 pm
- Location: Uruguay
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
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