| |  |  | Miembros: Mensajes: Temas: Online: Ultimo Miembro: | | | 
12-01-2005, 13:55:35
|  | Moderador | | Registrado: ene 2005 Ubicación: Curico Posts: 771
| | Transformar números a palabras... Estoy haciendo un formulario para facturación y tengo que transformar el valor final en pesos a palabras...
Por ejemplo 125.346 = "Ciento veinte y cinco mil trecientos cuarenta y seis"...
Si pueden ayudarme estaré sumamente agradecido...
__________________
Atentamente, Juan Ríos Pizarro...
Saludos desde Chile...
PD: Perdí mi mascota... buaaaaaaaa.... al menos encontré una nueva | 
12-01-2005, 14:14:23
| | Un Nuevo Amigo | | Registrado: nov 2004 Posts: 24
| | Aquí te mando una función que yo encontré en un foro, no recuerdo cual, ni tampoco su autor para, como mínimo nombrarlo, esperando que como a mí te sirva de ayuda.
Un saludo. | 
12-01-2005, 14:35:13
|  | Moderador | | Registrado: ene 2005 Ubicación: Curico Posts: 771
| | Gracias...
__________________
Atentamente, Juan Ríos Pizarro...
Saludos desde Chile...
PD: Perdí mi mascota... buaaaaaaaa.... al menos encontré una nueva | 
12-01-2005, 16:17:59
|  | Administrator | | Registrado: dic 2002 Ubicación: BURGOS - ESPAÑA Posts: 5.100
| | Casi con toda seguridad el número que tú pones como ejemplo en el primer mensaje de este post no te lo va a convertir a "Ciento veinte y cinco mil trecientos cuarenta y seis", como tú querías, sino a "Ciento veinticinco mil trecientos cuarenta y seis"...
Supongo que en Chile también sea correcta esta segunda traducción; si no, ya sabes... Tendrás que hacer unas cuantas correcciones en el código. | 
20-05-2008, 17:47:01
| | Un Nuevo Amigo | | Registrado: may 2008 Posts: 2
| | Re: Transformar números a palabras... Cita:
Empezado por jrios03 Estoy haciendo un formulario para facturación y tengo que transformar el valor final en pesos a palabras...
Por ejemplo 125.346 = "Ciento veinte y cinco mil trecientos cuarenta y seis"...
Si pueden ayudarme estaré sumamente agradecido... | como ingreso este programa ? cuales son los pasos a seguir ?
gracias | 
20-05-2008, 17:48:37
| | Un Nuevo Amigo | | Registrado: may 2008 Posts: 2
| | Re: Transformar números a palabras... donde ingreso esta funcion ?
gracias | 
20-05-2008, 19:22:29
| | Buena Participación en el Foro | | Registrado: feb 2005 Ubicación: Detras de un monitor... Posts: 67
| | Re: Transformar números a palabras... Public Function SonEnPalabras(Cifra As Long) As String
If Cifra > 999999999 Then
SonEnPalabras = Cifra
Exit Function
End If
Dim CifraChr As String
Dim Millones As Boolean
Dim Mil As Boolean
CifraChr = ""
Dim Decenas(0 To 29)
Decenas(0) = " "
Decenas(1) = " UN "
Decenas(2) = " DOS "
Decenas(3) = " TRES "
Decenas(4) = " CUATRO "
Decenas(5) = " CINCO "
Decenas(6) = " SEIS "
Decenas(7) = " SIETE "
Decenas(8) = " OCHO "
Decenas(9) = " NUEVE "
Decenas(10) = " DIEZ "
Decenas(11) = " ONCE "
Decenas(12) = " DOCE "
Decenas(13) = " TRECE "
Decenas(14) = " CATORCE "
Decenas(15) = " QUINCE "
Decenas(16) = " DIECISEIS "
Decenas(17) = " DIECISIETE "
Decenas(18) = " DIECIOCHO "
Decenas(19) = " DIECINUEVE "
Decenas(20) = " VEINTE "
Decenas(21) = " VEINTIUN "
Decenas(22) = " VEINTIDOS "
Decenas(23) = " VEINTITRES "
Decenas(24) = " VEINTICUATRO "
Decenas(25) = " VEINTICINCO "
Decenas(26) = " VEINTISEIS "
Decenas(27) = " VEINTISIETE "
Decenas(28) = " VEINTIOCHO "
Decenas(29) = " VEINTINUEVE "
Dim Decenas2(3 To 9)
Decenas2(3) = " TREINTA "
Decenas2(4) = " CUARENTA "
Decenas2(5) = " CINCUENTA "
Decenas2(6) = " SESENTA "
Decenas2(7) = " SETENTA "
Decenas2(8) = " OCHENTA "
Decenas2(9) = " NOVENTA "
Dim Centenas(1 To 9)
Centenas(1) = " CIENTO "
Centenas(2) = " DOSCIENTOS "
Centenas(3) = " TRESCIENTOS "
Centenas(4) = " CUATROCIENTOS "
Centenas(5) = " QUINIENTOS "
Centenas(6) = " SEISCIENTOS "
Centenas(7) = " SETECIENTOS "
Centenas(8) = " OCHOCIENTOS "
Centenas(9) = " NOVECIENTOS "
If Cifra = 0 Then
SonEnPalabras = "CERO PESOS"
Exit Function
End If
If Cifra < 0 Then
CifraChr = " MENOS "
Cifra = Cifra * -1
End If
' -------- Millones -------
If Cifra >= 100000000 And Cifra <= 100999999 Then
CifraChr = CifraChr & " CIEN "
Cifra = Cifra - 100000000
Millones = True
End If
If Cifra > 100999999 Then
CifraChr = CifraChr & Centenas(Int(Cifra / 100000000))
Cifra = Cifra - (Int(Cifra / 100000000) * 100000000)
Millones = True
End If
If Cifra > 999999 And Cifra <= 1999999 Then
CifraChr = CifraChr & " UN MILLON "
Cifra = Cifra - 1000000
Millones = False
ElseIf Cifra > 1999999 And Cifra <= 29999999 Then
CifraChr = CifraChr & Decenas(Int(Cifra / 1000000))
Cifra = Cifra - (Int(Cifra / 1000000) * 1000000)
Millones = True
ElseIf Cifra > 29999999 Then
CifraChr = CifraChr & Decenas2(Int(Cifra / 10000000))
Cifra = Cifra - (Int(Cifra / 10000000) * 10000000)
If Cifra > 999999 Then
CifraChr = CifraChr & " Y "
CifraChr = CifraChr & Decenas(Int(Cifra / 1000000))
Cifra = Cifra - (Int(Cifra / 1000000) * 1000000)
End If
Millones = True
End If
If Millones Then
CifraChr = CifraChr & " MILLONES "
End If
If CifraChr <> "" And Cifra = 0 Then
CifraChr = CifraChr & " DE "
End If
'------------ Miles ------------
If Cifra >= 100000 And Cifra <= 100999 Then
CifraChr = CifraChr & " CIEN "
Cifra = Cifra - 100000
Miles = True
End If
If Cifra > 100999 Then
CifraChr = CifraChr & Centenas(Int(Cifra / 100000))
Cifra = Cifra - (Int(Cifra / 100000) * 100000)
Miles = True
End If
If Cifra > 999 And Cifra <= 1999 Then
If CifraChr = "" Then
CifraChr = CifraChr & " MIL "
Else
CifraChr = CifraChr & " UN MIL "
End If
Cifra = Cifra - 1000
Miles = False
ElseIf Cifra > 1999 And Cifra <= 29999 Then
CifraChr = CifraChr & Decenas(Int(Cifra / 1000))
Cifra = Cifra - (Int(Cifra / 1000) * 1000)
Miles = True
ElseIf Cifra > 29999 Then
CifraChr = CifraChr & Decenas2(Int(Cifra / 10000))
Cifra = Cifra - (Int(Cifra / 10000) * 10000)
If Cifra > 999 Then
CifraChr = CifraChr & " Y "
CifraChr = CifraChr & Decenas(Int(Cifra / 1000))
Cifra = Cifra - (Int(Cifra / 1000) * 1000)
End If
Miles = True
End If
If Miles Then
CifraChr = CifraChr & " MIL "
End If
'------------ Las Chauchas ------------
If Cifra = 100 Then
CifraChr = CifraChr & " CIEN "
Cifra = Cifra - 100
End If
If Cifra > 100 Then
CifraChr = CifraChr & Centenas(Int(Cifra / 100))
Cifra = Cifra - (Int(Cifra / 100) * 100)
End If
If Cifra > 0 And Cifra <= 29 Then
CifraChr = CifraChr & Decenas(Cifra)
ElseIf Cifra > 29 Then
CifraChr = CifraChr & Decenas2(Int(Cifra / 10))
Cifra = Cifra - (Int(Cifra / 10) * 10)
If Cifra > 0 Then
CifraChr = CifraChr & " Y "
CifraChr = CifraChr & Decenas(Cifra)
End If
End If
CifraChr = CifraChr & " PESOS"
CifraChr = LTrim(RTrim(CifraChr))
Dim Encontrado As Integer
Encontrado = InStr(1, CifraChr, " ")
Do Until Not Encontrado
CifraChr = Left(CifraChr, Encontrado - 1) & Mid$(CifraChr, Encontrado + 1)
Encontrado = InStr(1, CifraChr, " ")
Loop
CifraChr = Left(CifraChr, 1) & LCase(Mid$(CifraChr, 2))
SonEnPalabras = CifraChr
End Function
Ponela en un modulo,
Para los decimales, primero manda la parte entera, concatenas la coma y luego la parte decimal.
Espero te sea de ayuda.
__________________
---------------------
Ácido, pero vitamínico.
Maipú- Chile
| 
21-05-2008, 23:47:49
|  | Moderador | | Registrado: nov 2007 Ubicación: Argentina Posts: 321
| | Re: Transformar números a palabras... Hola,te paso un modulo clase que use en un conversor de unidades de medidas.. Código: Option Explicit
Private astrConversor(0 To 2, 1 To 9) As String
Private mvarNumero As Variant
Public Property Let Numero(ByVal vData As Variant)
If IsNumeric(vData) Then
mvarNumero = vData
End If
End Property
Public Property Get Numero() As Variant
Numero = mvarNumero
End Property
Public Function ALetra() As String
Dim i As Integer
Dim intProceder As Integer
Dim intPosNumero As Integer
Dim intLongNumero As Integer
Dim strNumero As String
Dim strLetraNumero As String
mvarNumero = Abs(mvarNumero)
strNumero = CStr(Fix(mvarNumero))
intLongNumero = Len(strNumero)
intPosNumero = intLongNumero
For i = 1 To intLongNumero
intProceder = True
If (intPosNumero Mod 3) = 1 Then
If intLongNumero > intPosNumero Then
Select Case Mid(strNumero, i - 1, 2)
Case "00"
If UCase(Right(strLetraNumero, 7)) = "CIENTO " Then
strLetraNumero = Left(strLetraNumero, Len(strLetraNumero) - 7)
strLetraNumero = strLetraNumero & "Cien "
End If
Case "11"
strLetraNumero = Left(strLetraNumero, Len(strLetraNumero) - 5)
strLetraNumero = strLetraNumero & "Once "
intProceder = False
Case "12"
strLetraNumero = Left(strLetraNumero, Len(strLetraNumero) - 5)
strLetraNumero = strLetraNumero & "Doce "
intProceder = False
Case "13"
strLetraNumero = Left(strLetraNumero, Len(strLetraNumero) - 5)
strLetraNumero = strLetraNumero & "Trece "
intProceder = False
Case "14"
strLetraNumero = Left(strLetraNumero, Len(strLetraNumero) - 5)
strLetraNumero = strLetraNumero & "Catorce "
intProceder = False
Case "15"
strLetraNumero = Left(strLetraNumero, Len(strLetraNumero) - 5)
strLetraNumero = strLetraNumero & "Quince "
intProceder = False
Case "16", "17", "18", "19"
strLetraNumero = Left(strLetraNumero, Len(strLetraNumero) - 2)
strLetraNumero = strLetraNumero & "ci"
Case "21" To "29"
strLetraNumero = Left(strLetraNumero, Len(strLetraNumero) - 2)
strLetraNumero = strLetraNumero & "i"
Case Else
If Val(Mid(strNumero, i, 1)) > 0 And Val(Mid(strNumero, i - 1, 1)) > 0 Then
strLetraNumero = strLetraNumero & "y "
End If
End Select
End If
End If
If Val(Mid(strNumero, i, 1)) > 0 And intProceder Then
strLetraNumero = strLetraNumero & astrConversor((intPosNumero Mod 3), Val(Mid(strNumero, i, 1))) & " "
End If
Select Case intPosNumero
Case 4
If Right(strLetraNumero, 9) <> "millones " And Right(strLetraNumero, 13) <> "mil millones " And Right(strLetraNumero, 9) <> "billones " Then
strLetraNumero = strLetraNumero & "mil "
End If
Case 7
If Right(strLetraNumero, 13) <> "mil millones " And Right(strLetraNumero, 9) <> "billones " Then
strLetraNumero = strLetraNumero & "millones "
End If
Case 10
If Right(strLetraNumero, 9) <> "billones " Then
strLetraNumero = strLetraNumero & "mil "
End If
Case 13
strLetraNumero = strLetraNumero & "billones "
Case Else
End Select
intPosNumero = intPosNumero - 1
Next i
strLetraNumero = Left(strLetraNumero, 1) & LCase(Mid(strLetraNumero, 2))
ALetra = strLetraNumero
End Function
Private Sub Asigna()
astrConversor(0, 1) = "Ciento"
astrConversor(0, 2) = "Doscientos"
astrConversor(0, 3) = "Trescientos"
astrConversor(0, 4) = "Cuatrocientos"
astrConversor(0, 5) = "Quinientos"
astrConversor(0, 6) = "Seiscientos"
astrConversor(0, 7) = "Setecientos"
astrConversor(0, 8) = "Ochocientos"
astrConversor(0, 9) = "Novecientos"
astrConversor(1, 1) = "Uno"
astrConversor(1, 2) = "Dos"
astrConversor(1, 3) = "Tres"
astrConversor(1, 4) = "Cuatro"
astrConversor(1, 5) = "Cinco"
astrConversor(1, 6) = "Seis"
astrConversor(1, 7) = "Siete"
astrConversor(1, 8) = "Ocho"
astrConversor(1, 9) = "Nueve"
astrConversor(2, 1) = "Diez"
astrConversor(2, 2) = "Veinte"
astrConversor(2, 3) = "Treinta"
astrConversor(2, 4) = "Cuarenta"
astrConversor(2, 5) = "Cincuenta"
astrConversor(2, 6) = "Sesenta"
astrConversor(2, 7) = "Setenta"
astrConversor(2, 8) = "Ochenta"
astrConversor(2, 9) = "Noventa"
End Sub
Private Sub Class_Initialize()
Asigna
End Sub
Private Sub Class_Terminate()
Erase astrConversor
End Sub en un formulario con 2 textbox escribi esto: Código: Private Conversor As New Class1
Private Sub Text1_Change()
Conversor.Numero = Val(Text1.Text)
Text2.Text = Conversor.ALetra
End Sub aguanta hasta 999999999999999 o sea, "Novecientos noventa y nueve billones novecientos noventa y nueve mil novecientos noventa y nueve millones novecientos noventa y nueve mil novecientos noventa y nueve "
saludos.
__________________ Todos somos ignorantes; lo que pasa es que no todos ignoramos las mismas cosas - Albert Einstein | | Herramientas | | | | Desplegado | Mode Lineal |
Normas de Publicación
| no Puedes crear nuevos temas no Puedes responder a temas no Puedes adjuntar archivos no Puedes editar tus mensajes Código [IMG] está habilitado Código HTML está deshabilitado | | | La franja horaria es GMT. Ahora son las 05:55:20.
Powered by vBulletin® Version 3.6.8 Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO 3.1.0
A vBSkinworks Design
|  |