Foros del Web » Programando para Internet » ASP Clásico »

Pasar numeros a palabras...

Estas en el tema de Pasar numeros a palabras... en el foro de ASP Clásico en Foros del Web. Hola amigos, alguien tiene algun script donde yo escriba por ejemplo : 120 y me entregue en palabras : ciento veinte o 40240 y escriba ...
  #1 (permalink)  
Antiguo 18/12/2003, 09:50
 
Fecha de Ingreso: julio-2002
Ubicación: Stgo
Mensajes: 164
Antigüedad: 22 años, 9 meses
Puntos: 0
Pasar numeros a palabras...

Hola amigos, alguien tiene algun script
donde yo escriba por ejemplo :

120

y me entregue en palabras : ciento veinte

o

40240

y escriba : Cuarenta Mil Dociento cuarenta ?


por fa.. si alguien lo ha hecho o sabe como hacerlo, que me diga

saluda atte
Canicas jr.
__________________
Saludos
Alejandro Antonio :-D
from ChiLE :pensando:
[email protected]
icq:14648436
[email protected]
  #2 (permalink)  
Antiguo 18/12/2003, 11:18
Avatar de AlZuwaga
Colaborador
 
Fecha de Ingreso: febrero-2001
Ubicación: 34.517 S, 58.500 O
Mensajes: 14.550
Antigüedad: 24 años, 2 meses
Puntos: 535
Fijate si te sirve. Copiá y pegá todo esto en una página que se llame "monto_escrito.asp" y probalo:


<html>

<head>
<title>Monto escrito</title>
</head>

<body>
<p align="center"><b><font face="Verdana">Convertidor de números a su valor en
letras<br>
By <a href="http://www.forosdelweb.com/member.php?s=&action=getinfo&userid=35429">Inutil</a></font></b></p>
<p>_</p>
<form action="monto_escrito.asp" method="POST" name="Form" id="Form">
<p><font face="Verdana" size="1">Escriba sólo números enteros, sin
puntuación de miles:</font><br>
<input type="text" name="NUMERO" size="40" style="font-family: Verdana; font-size: 8 pt">
<input type="submit" value="Dale gas!" name="B1" style="font-family: Verdana; font-size: 8 pt"></p>
</form>

<p>
<font face="Verdana" size="2">
<%
on error resume next
Accion = Request.Form("NUMERO")
numero_prueba = Accion
numero_prueba = FormatNumber(numero_prueba,0)

If Accion = "" then
Else
%>

<%
dim unidad(9), decena(9), centena(10), deci(9), otros(15)
Sub InicializarArrays()
unidad(1) = "una" & "&nbsp;"
unidad(2) = "dos" & "&nbsp;"
unidad(3) = "tres" & "&nbsp;"
unidad(4) = "cuatro" & "&nbsp;"
unidad(5) = "cinco" & "&nbsp;"
unidad(6) = "seis" & "&nbsp;"
unidad(7) = "siete" & "&nbsp;"
unidad(8) = "ocho" & "&nbsp;"
unidad(9) = "nueve" & "&nbsp;"
'
decena(1) = "diez" & "&nbsp;"
decena(2) = "veinte" & "&nbsp;"
decena(3) = "treinta" & "&nbsp;"
decena(4) = "cuarenta" & "&nbsp;"
decena(5) = "cincuenta" & "&nbsp;"
decena(6) = "sesenta" & "&nbsp;"
decena(7) = "setenta" & "&nbsp;"
decena(8) = "ochenta" & "&nbsp;"
decena(9) = "noventa" & "&nbsp;"
'
centena(1) = "ciento" & "&nbsp;"
centena(2) = "doscientos" & "&nbsp;"
centena(3) = "trescientos" & "&nbsp;"
centena(4) = "cuatrocientos" & "&nbsp;"
centena(5) = "quinientos" & "&nbsp;"
centena(6) = "seiscientos" & "&nbsp;"
centena(7) = "setecientos" & "&nbsp;"
centena(8) = "ochocientos" & "&nbsp;"
centena(9) = "novecientos" & "&nbsp;"
centena(10) = "cien" & "&nbsp;"
'
deci(1) = "dieci" & "&nbsp;"
deci(2) = "veinti"' & "&nbsp;"
deci(3) = "treinta" & "&nbsp;" &"y" & "&nbsp;"
deci(4) = "cuarenta" & "&nbsp;" &"y" & "&nbsp;"
deci(5) = "cincuenta" & "&nbsp;" &"y" & "&nbsp;"
deci(6) = "sesenta" & "&nbsp;" &"y" & "&nbsp;"
deci(7) = "setenta" & "&nbsp;" &"y" & "&nbsp;"
deci(8) = "ochenta" & "&nbsp;" &"y" & "&nbsp;"
deci(9) = "noventa" & "&nbsp;" &"y" & "&nbsp;"
'
otros(1) = "1"
otros(2) = "2"
otros(3) = "3"
otros(4) = "4"
otros(5) = "5"
otros(6) = "6"
otros(7) = "7"
otros(8) = "8"
otros(9) = "9"
otros(10) = "10"
otros(11) = "once" & "&nbsp;"
otros(12) = "doce" & "&nbsp;"
otros(13) = "trece" & "&nbsp;"
otros(14) = "catorce" & "&nbsp;"
otros(15) = "quince" & "&nbsp;"

End Sub

Function Numero2Letra(strNum , vLo, vMoneda, vCentimos)

If vMoneda<>"" Then
sMoneda = " " & Trim(vMoneda) & " "
Else
sMoneda = " "
End If
If vCentimos<>"" Then
sCentimos = " " & Trim(vCentimos)
End If

sNumero = Format(25.5, "#.#")
If InStr(sNumero, ".") Then
sDecimal = "."
Else
sDecimal = ","
End If

If IsMissing(vLo) Then
Lo = 0
Else
Lo = vLo
End If
'
If Lo Then
sNumero = Space(Lo)
Else
sNumero = ""
End If

Do
i = InStr(strNum, " ")
If i = 0 Then Exit Do
strNum = Left(strNum, i - 1) & Mid(strNum, i + 1)
Loop

iHayDecimal = InStr(strNum, sDecimal)
If iHayDecimal Then
sEntero = Left(strNum, iHayDecimal - 1)
sFraccion = Mid(strNum, iHayDecimal + 1) & "00"
sFraccion = Left(sFraccion, 2)
fFraccion = sFraccion

If fFraccion < 1 Then
strNum = RTrim(UnNumero(sEntero) & sMoneda)
sNumero = strNum

Numero2Letra = sNumero
Exit Function
End If

sEntero = UnNumero(sEntero)
sFraccion = UnNumero(sFraccion)
'
strNum = sEntero & sMoneda & "con " & sFraccion & sCentimos

sNumero = RTrim(strNum)

Numero2Letra = sNumero
Else
strNum = RTrim(UnNumero(strNum) & sMoneda)

sNumero = strNum

Numero2Letra = sNumero
End If
End Function

Function UnNumero(strNum)
Const cAncho = 12
cGrupos = cAncho / 3
lngA = Abs(CDbl(strNum))
Negativo = (lngA <> CDbl(strNum))
strNum = LTrim(RTrim(cStr(lngA)))
L = Len(strNum)

If lngA < 1 Then
UnNumero = "cero"
Exit Function
End If
Una = True
Millon = False
Millones = False
If L < 4 Then Una = False
If lngA > 999999 Then Millon = True
If lngA > 1999999 Then Millones = True
strB = ""
strQ = strNum
vez = 0

ReDim strN(cGrupos)
strQ = Right(String(cAncho, "0") & strNum, cAncho)
For k = Len(strQ) To 1 Step -3
vez = vez + 1
strN(vez) = Mid(strQ, k - 2, 3)
Next
MaxVez = cGrupos
For k = cGrupos To 1 Step -1
If strN(k) = "000" Then
MaxVez = MaxVez - 1
Else
Exit For
End If
Next
For vez = 1 To MaxVez
strU = "": strD = "": strC = ""
strNum = strN(vez)
L = Len(strNum)
k = Right(strNum, 2)
If Right(strNum, 1) = "0" Then
k = cInt(k) / 10
strD = decena(k)
ElseIf k > 10 And k < 16 Then
k = Mid(strNum, L - 1, 2)
strD = otros(k)
Else
strU = unidad(Right(strNum, 1))
If L - 1 > 0 Then
k = Mid(strNum, L - 1, 1)
strD = deci(k)
End If
End If

If L - 2 > 0 Then
k = Mid(strNum, L - 2, 1)
If k = 1 Then
If strNum = 100 Then
k = 10
End If
End If
strC = centena(k) & " "
End If

If strU = "uno" And Left(strB, 4) = " mil" & "&nbsp;" Then strU = ""
strB = strC & strD & strU & " " & strB

If (vez = 1 Or vez = 3) Then
If strN(vez + 1) <> "000" Then strB = " mil" & "&nbsp;" & strB
End If
If vez = 2 And Millon Then
If Millones Then
strB = " millones" & "&nbsp;" & strB
Else
strB = "un" & "&nbsp;" & "millón" & "&nbsp;" & strB
End If
End If
Next
strB = Trim(strB)
If Right(strB, 3) = "uno" Then strB = Left(strB, Len(strB) - 1) & "a"
Do
iA = InStr(strB, " ")
If iA = 0 Then Exit Do
strB = Left(strB, iA - 1) & Mid(strB, iA + 1)
Loop

If Left(strB, 6) = "una un" Then strB = Mid(strB, 5)
If Left(strB, 7) = "una mil" Then strB = Mid(strB, 5)
If Right(strB, 16) <> "millones mil una" Then
iA = InStr(strB, "millones mil una")
If iA Then strB = Left(strB, iA + 8) & Mid(strB, iA + 13)
End If
If Right(strB, 6) = "ciento" Then strB = Left(strB, Len(strB) - 2)
If Negativo Then strB = "menos " & strB
UnNumero = Trim(strB)
End Function

InicializarArrays
Response.Write(Numero_Prueba & ": " & unNumero(Accion) & "<br>")
'Response.Write(": " & unNumero(Accion) & "<br>")
Response.Write("1: " & unNumero(1) & "<br>")
%>
<%
End if
%>
</font>
</p>
<p>_</p>
</body>

</html>



Saludos
  #3 (permalink)  
Antiguo 20/12/2003, 09:10
 
Fecha de Ingreso: julio-2002
Ubicación: Stgo
Mensajes: 164
Antigüedad: 22 años, 9 meses
Puntos: 0
LO VOY A PROBAR Y TE CUENTO

GRACIASSS SOCIO :)
__________________
Saludos
Alejandro Antonio :-D
from ChiLE :pensando:
[email protected]
icq:14648436
[email protected]
  #4 (permalink)  
Antiguo 26/12/2003, 18:28
 
Fecha de Ingreso: julio-2002
Ubicación: Stgo
Mensajes: 164
Antigüedad: 22 años, 9 meses
Puntos: 0
socio,
mira ahi está corriendo ... pero tengo un problema con montos grandes...

http://www.colegioantupiren.cl/monto_escrito.asp

miles.... millones, cientos...

además que pongo espacios y no los toma.....

sabes que puede ser ? ..

saludos
alejandro
__________________
Saludos
Alejandro Antonio :-D
from ChiLE :pensando:
[email protected]
icq:14648436
[email protected]
  #5 (permalink)  
Antiguo 30/12/2003, 07:28
 
Fecha de Ingreso: julio-2002
Ubicación: Stgo
Mensajes: 164
Antigüedad: 22 años, 9 meses
Puntos: 0
????? por fa.......

HELP ME
__________________
Saludos
Alejandro Antonio :-D
from ChiLE :pensando:
[email protected]
icq:14648436
[email protected]
  #6 (permalink)  
Antiguo 30/12/2003, 12:31
Avatar de AlZuwaga
Colaborador
 
Fecha de Ingreso: febrero-2001
Ubicación: 34.517 S, 58.500 O
Mensajes: 14.550
Antigüedad: 24 años, 2 meses
Puntos: 535
mmm... tal vez el foro jodío algo.. lo pongo de nuevo dentro de CODE a ver que onda:

Código:
<html>

<head>
<title>Monto escrito</title>
</head>

<body>
<p align="center"><b><font face="Verdana">Convertidor de números a su valor en
letras<br>
By <a href="http://www.forosdelweb.com/member.php?s=&action=getinfo&userid=35429">Inutil</a></font></b></p>
<p>_</p>
<form action="monto_escrito.asp" method="POST" name="Form" id="Form">
  <p><font face="Verdana" size="1">Escriba sólo números enteros, sin
  puntuación de miles:</font><br>
  <input type="text" name="NUMERO" size="40" style="font-family: Verdana; font-size: 8 pt">
  <input type="submit" value="Dale gas!" name="B1" style="font-family: Verdana; font-size: 8 pt"></p>
</form>

<p>
<font face="Verdana" size="2">
<%
on error resume next
Accion = Request.Form("NUMERO")
numero_prueba = Accion
numero_prueba = FormatNumber(numero_prueba,0)

If Accion = "" then
Else
%>

<%
dim unidad(9), decena(9), centena(10), deci(9), otros(15)
Sub InicializarArrays()
unidad(1) = "una" & "&nbsp;"
unidad(2) = "dos" & "&nbsp;"
unidad(3) = "tres" & "&nbsp;"
unidad(4) = "cuatro" & "&nbsp;"
unidad(5) = "cinco" & "&nbsp;"
unidad(6) = "seis" & "&nbsp;"
unidad(7) = "siete" & "&nbsp;"
unidad(8) = "ocho" & "&nbsp;"
unidad(9) = "nueve" & "&nbsp;"
'
decena(1) = "diez" & "&nbsp;"
decena(2) = "veinte" & "&nbsp;"
decena(3) = "treinta" & "&nbsp;"
decena(4) = "cuarenta" & "&nbsp;"
decena(5) = "cincuenta" & "&nbsp;"
decena(6) = "sesenta" & "&nbsp;"
decena(7) = "setenta" & "&nbsp;"
decena(8) = "ochenta" & "&nbsp;"
decena(9) = "noventa" & "&nbsp;"
'
centena(1) = "ciento" & "&nbsp;"
centena(2) = "doscientos" & "&nbsp;"
centena(3) = "trescientos" & "&nbsp;"
centena(4) = "cuatrocientos" & "&nbsp;"
centena(5) = "quinientos" & "&nbsp;"
centena(6) = "seiscientos" & "&nbsp;"
centena(7) = "setecientos" & "&nbsp;"
centena(8) = "ochocientos" & "&nbsp;"
centena(9) = "novecientos" & "&nbsp;"
centena(10) = "cien" & "&nbsp;"
'
deci(1) = "dieci" & "&nbsp;"
deci(2) = "veinti"' & "&nbsp;"
deci(3) = "treinta" & "&nbsp;" &"y" & "&nbsp;"
deci(4) = "cuarenta" & "&nbsp;" &"y" & "&nbsp;"
deci(5) = "cincuenta" & "&nbsp;" &"y" & "&nbsp;"
deci(6) = "sesenta" & "&nbsp;" &"y" & "&nbsp;"
deci(7) = "setenta" & "&nbsp;" &"y" & "&nbsp;"
deci(8) = "ochenta" & "&nbsp;" &"y" & "&nbsp;"
deci(9) = "noventa" & "&nbsp;" &"y" & "&nbsp;"
'
otros(1) = "1"
otros(2) = "2"
otros(3) = "3"
otros(4) = "4"
otros(5) = "5"
otros(6) = "6"
otros(7) = "7"
otros(8) = "8"
otros(9) = "9"
otros(10) = "10"
otros(11) = "once" & "&nbsp;"
otros(12) = "doce" & "&nbsp;"
otros(13) = "trece" & "&nbsp;"
otros(14) = "catorce" & "&nbsp;"
otros(15) = "quince" & "&nbsp;"

End Sub

Function Numero2Letra(strNum , vLo, vMoneda, vCentimos)

If vMoneda<>"" Then
sMoneda = " " & Trim(vMoneda) & " "
Else
sMoneda = " "
End If
If vCentimos<>"" Then
sCentimos = " " & Trim(vCentimos)
End If

sNumero = Format(25.5, "#.#")
If InStr(sNumero, ".") Then
sDecimal = "."
Else
sDecimal = ","
End If

If IsMissing(vLo) Then
Lo = 0
Else
Lo = vLo
End If
'
If Lo Then
sNumero = Space(Lo)
Else
sNumero = ""
End If

Do
i = InStr(strNum, " ")
If i = 0 Then Exit Do
strNum = Left(strNum, i - 1) & Mid(strNum, i + 1)
Loop

iHayDecimal = InStr(strNum, sDecimal)
If iHayDecimal Then
sEntero = Left(strNum, iHayDecimal - 1)
sFraccion = Mid(strNum, iHayDecimal + 1) & "00"
sFraccion = Left(sFraccion, 2)
fFraccion = sFraccion

If fFraccion < 1 Then
strNum = RTrim(UnNumero(sEntero) & sMoneda)
sNumero = strNum

Numero2Letra = sNumero
Exit Function
End If

sEntero = UnNumero(sEntero)
sFraccion = UnNumero(sFraccion)
'
strNum = sEntero & sMoneda & "con " & sFraccion & sCentimos

sNumero = RTrim(strNum)

Numero2Letra = sNumero
Else
strNum = RTrim(UnNumero(strNum) & sMoneda)

sNumero = strNum

Numero2Letra = sNumero
End If
End Function

Function UnNumero(strNum) 
Const cAncho = 12
cGrupos = cAncho / 3
lngA = Abs(CDbl(strNum))
Negativo = (lngA <> CDbl(strNum))
strNum = LTrim(RTrim(cStr(lngA)))
L = Len(strNum)

If lngA < 1 Then
UnNumero = "cero"
Exit Function
End If
Una = True
Millon = False
Millones = False
If L < 4 Then Una = False
If lngA > 999999 Then Millon = True
If lngA > 1999999 Then Millones = True
strB = ""
strQ = strNum
vez = 0

ReDim strN(cGrupos)
strQ = Right(String(cAncho, "0") & strNum, cAncho)
For k = Len(strQ) To 1 Step -3
vez = vez + 1
strN(vez) = Mid(strQ, k - 2, 3)
Next
MaxVez = cGrupos
For k = cGrupos To 1 Step -1
If strN(k) = "000" Then
MaxVez = MaxVez - 1
Else
Exit For
End If
Next
For vez = 1 To MaxVez
strU = "": strD = "": strC = ""
strNum = strN(vez)
L = Len(strNum)
k = Right(strNum, 2)
If Right(strNum, 1) = "0" Then
k = cInt(k) / 10
strD = decena(k)
ElseIf k > 10 And k < 16 Then
k = Mid(strNum, L - 1, 2)
strD = otros(k)
Else
strU = unidad(Right(strNum, 1))
If L - 1 > 0 Then
k = Mid(strNum, L - 1, 1)
strD = deci(k)
End If
End If

If L - 2 > 0 Then
k = Mid(strNum, L - 2, 1) 
If k = 1 Then
If strNum = 100 Then
k = 10
End If
End If
strC = centena(k) & " "
End If

If strU = "uno" And Left(strB, 4) = " mil" & "&nbsp;" Then strU = ""
strB = strC & strD & strU & " " & strB

If (vez = 1 Or vez = 3) Then
If strN(vez + 1) <> "000" Then strB = " mil" & "&nbsp;" & strB
End If
If vez = 2 And Millon Then
If Millones Then
strB = " millones" & "&nbsp;" & strB
Else
strB = "un" & "&nbsp;" & "millón" & "&nbsp;" & strB
End If
End If
Next
strB = Trim(strB)
If Right(strB, 3) = "uno" Then strB = Left(strB, Len(strB) - 1) & "a"
Do
iA = InStr(strB, " ")
If iA = 0 Then Exit Do
strB = Left(strB, iA - 1) & Mid(strB, iA + 1)
Loop

If Left(strB, 6) = "una un" Then strB = Mid(strB, 5)
If Left(strB, 7) = "una mil" Then strB = Mid(strB, 5)
If Right(strB, 16) <> "millones mil una" Then
iA = InStr(strB, "millones mil una")
If iA Then strB = Left(strB, iA + 8) & Mid(strB, iA + 13)
End If
If Right(strB, 6) = "ciento" Then strB = Left(strB, Len(strB) - 2)
If Negativo Then strB = "menos " & strB
UnNumero = Trim(strB)
End Function

InicializarArrays
Response.Write(Numero_Prueba & ": " & unNumero(Accion) & "<br>")
'Response.Write(": " & unNumero(Accion) & "<br>")
Response.Write("1: " & unNumero(1) & "<br>")
%>
<%
End if
%>
</font>
</p>
<p>_</p>
</body>

</html>
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 15:31.