He visto muchas veces esta pregunta en los foros, si mal no recuerdo en el año 2000 alguién que no recuerdo su nombre envío el siguiente algoritmo para VB 6.0 para realizar dicha conversión…. ha sido unos de los mejores que he visto.. a continuación se los adjunto, espero que también les puedan servir.
Sirve tanto para VB 6.0, como para Visual Basic .NET
Public Function Num2Text(ByVal value As Double) As String
Select Case value
Case 0 : Num2Text = “CERO”
Case 1 : Num2Text = “UN”
Case 2 : Num2Text = “DOS”
Case 3 : Num2Text = “TRES”
Case 4 : Num2Text = “CUATRO”
Case 5 : Num2Text = “CINCO”
Case 6 : Num2Text = “SEIS”
Case 7 : Num2Text = “SIETE”
Case 8 : Num2Text = “OCHO”
Case 9 : Num2Text = “NUEVE”
Case 10 : Num2Text = “DIEZ”
Case 11 : Num2Text = “ONCE”
Case 12 : Num2Text = “DOCE”
Case 13 : Num2Text = “TRECE”
Case 14 : Num2Text = “CATORCE”
Case 15 : Num2Text = “QUINCE”
Case Is < 20 : Num2Text = “DIECI” & Num2Text(value – 10)
Case 20 : Num2Text = “VEINTE”
Case Is < 30 : Num2Text = “VEINTI” & Num2Text(value – 20)
Case 30 : Num2Text = “TREINTA”
Case 40 : Num2Text = “CUARENTA”
Case 50 : Num2Text = “CINCUENTA”
Case 60 : Num2Text = “SESENTA”
Case 70 : Num2Text = “SETENTA”
Case 80 : Num2Text = “OCHENTA”
Case 90 : Num2Text = “NOVENTA”
Case Is < 100 : Num2Text = Num2Text(Int(value \ 10) * 10) & ” Y ” & Num2Text(value Mod 10)
Case 100 : Num2Text = “CIEN”
Case Is < 200 : Num2Text = “CIENTO ” & Num2Text(value – 100)
Case 200, 300, 400, 600, 800 : Num2Text = Num2Text(Int(value \ 100)) & “CIENTOS”
Case 500 : Num2Text = “QUINIENTOS”
Case 700 : Num2Text = “SETECIENTOS”
Case 900 : Num2Text = “NOVECIENTOS”
Case Is < 1000 : Num2Text = Num2Text(Int(value \ 100) * 100) & ” ” & Num2Text(value Mod 100)
Case 1000 : Num2Text = “MIL”
Case Is < 2000 : Num2Text = “MIL ” & Num2Text(value Mod 1000)
Case Is < 1000000 : Num2Text = Num2Text(Int(value \ 1000)) & ” MIL”
If value Mod 1000 Then Num2Text = Num2Text & ” ” & Num2Text(value Mod 1000)
Case 1000000 : Num2Text = “UN MILLON”
Case Is < 2000000 : Num2Text = “UN MILLON ” & Num2Text(value Mod 1000000)
Case Is < 1000000000000.0# : Num2Text = Num2Text(Int(value / 1000000)) & ” MILLONES “
If (value – Int(value / 1000000) * 1000000) Then Num2Text = Num2Text & ” ” & Num2Text(value – Int(value / 1000000) * 1000000)
Case 1000000000000.0# : Num2Text = “UN BILLON”
Case Is < 2000000000000.0# : Num2Text = “UN BILLON ” & Num2Text(value – Int(value / 1000000000000.0#) * 1000000000000.0#)
Case Else : Num2Text = Num2Text(Int(value / 1000000000000.0#)) & ” BILLONES”
If (value – Int(value / 1000000000000.0#) * 1000000000000.0#) Then Num2Text = Num2Text & ” ” & Num2Text(value – Int(value / 1000000000000.0#) * 1000000000000.0#)
End Select
Select Case value
Case 0 : Num2Text = “CERO”
Case 1 : Num2Text = “UN”
Case 2 : Num2Text = “DOS”
Case 3 : Num2Text = “TRES”
Case 4 : Num2Text = “CUATRO”
Case 5 : Num2Text = “CINCO”
Case 6 : Num2Text = “SEIS”
Case 7 : Num2Text = “SIETE”
Case 8 : Num2Text = “OCHO”
Case 9 : Num2Text = “NUEVE”
Case 10 : Num2Text = “DIEZ”
Case 11 : Num2Text = “ONCE”
Case 12 : Num2Text = “DOCE”
Case 13 : Num2Text = “TRECE”
Case 14 : Num2Text = “CATORCE”
Case 15 : Num2Text = “QUINCE”
Case Is < 20 : Num2Text = “DIECI” & Num2Text(value – 10)
Case 20 : Num2Text = “VEINTE”
Case Is < 30 : Num2Text = “VEINTI” & Num2Text(value – 20)
Case 30 : Num2Text = “TREINTA”
Case 40 : Num2Text = “CUARENTA”
Case 50 : Num2Text = “CINCUENTA”
Case 60 : Num2Text = “SESENTA”
Case 70 : Num2Text = “SETENTA”
Case 80 : Num2Text = “OCHENTA”
Case 90 : Num2Text = “NOVENTA”
Case Is < 100 : Num2Text = Num2Text(Int(value \ 10) * 10) & ” Y ” & Num2Text(value Mod 10)
Case 100 : Num2Text = “CIEN”
Case Is < 200 : Num2Text = “CIENTO ” & Num2Text(value – 100)
Case 200, 300, 400, 600, 800 : Num2Text = Num2Text(Int(value \ 100)) & “CIENTOS”
Case 500 : Num2Text = “QUINIENTOS”
Case 700 : Num2Text = “SETECIENTOS”
Case 900 : Num2Text = “NOVECIENTOS”
Case Is < 1000 : Num2Text = Num2Text(Int(value \ 100) * 100) & ” ” & Num2Text(value Mod 100)
Case 1000 : Num2Text = “MIL”
Case Is < 2000 : Num2Text = “MIL ” & Num2Text(value Mod 1000)
Case Is < 1000000 : Num2Text = Num2Text(Int(value \ 1000)) & ” MIL”
If value Mod 1000 Then Num2Text = Num2Text & ” ” & Num2Text(value Mod 1000)
Case 1000000 : Num2Text = “UN MILLON”
Case Is < 2000000 : Num2Text = “UN MILLON ” & Num2Text(value Mod 1000000)
Case Is < 1000000000000.0# : Num2Text = Num2Text(Int(value / 1000000)) & ” MILLONES “
If (value – Int(value / 1000000) * 1000000) Then Num2Text = Num2Text & ” ” & Num2Text(value – Int(value / 1000000) * 1000000)
Case 1000000000000.0# : Num2Text = “UN BILLON”
Case Is < 2000000000000.0# : Num2Text = “UN BILLON ” & Num2Text(value – Int(value / 1000000000000.0#) * 1000000000000.0#)
Case Else : Num2Text = Num2Text(Int(value / 1000000000000.0#)) & ” BILLONES”
If (value – Int(value / 1000000000000.0#) * 1000000000000.0#) Then Num2Text = Num2Text & ” ” & Num2Text(value – Int(value / 1000000000000.0#) * 1000000000000.0#)
End Select
End Function
existen versiones de este codigo para otros lenguajes, como javascript o asp (no .net)?
codigo de convertir numero a letras
como convierto de decimales a romanos pero hasta el 9999999 de los romanos
y como ponerle la rayita que lleva arriba la m del millon
si me puedes ayudar te lo agradecere
saludos gracias
hola excelente la funcion pero deseo fuera con decimales si me lo puedes enviar a fimacoi@yahoo.com
Gracias por tu aporte.
Saludos
alfonlt@hotmail.com
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim largo = Len(CStr(Format(CDbl(tnumero.Text), “#,###.00”)))
Dim decimales = Mid(CStr(Format(CDbl(tnumero.Text), “#,###.00”)), largo – 2)
tletras.Text = Num2Text(tnumero.Text – decimales) & ” ” & Mid(decimales, Len(decimales) – 1) & “/100″ & ” DOLARES.”
End Sub
como ejecuto esta funcion en visual
Buen código, me sirvió perfectamente.
Para el caso de números con decimales, una leve variación al caso previo, con truncado.
Saludos,
EleAEse
Public Function NumeroATexto(ByVal d As Double) As String
Dim parteEntera As Double = Math.Truncate(d)
Dim parteDecimal As Double = Math.Truncate((d – _parteEntera) * 100)
If (parteDecimal > 0) Then
return Num2Text(parteEntera) + " CON " Num2Text(parteDecimal) + " CENTAVOS"
Else
return Num2Text(parteEntera)
End if
end if
Falló con decimales
gracias por la funcion me sirviomucho
yo no le entendi nada al codigo :(, no me funciono, donde meto la funcion?? en un boton??
En un formulario, en un modulo, en un módulo de clases, donde tu quieras.
Me vino genial el codigo, y muchas gracias tambien a EleAEse por la parte decimal, es justo lo que necesitaba.
Contestando a cecy, las funciones no son para ejecutarlas directamente, tienes que llamar a ellas, un ejemplo.
Copia todo el codigo en cualquier parte como dijo jvargas, crea un TextBox y ahora si en un boton escribe:
TextBox1.Text = Num2Text(numero)
Eso escribira en el textbox el resultado de la funcion de Num2Text, las letras vaya… en numero obviamente tienes que poner un numero cualquiera o se lo pasas por otro textbox
Saludos
procedimiento para convertir números a letras en VISUAL BASIC 5.0
que referencias debo usar para el math.truncate??
GRACIAS POR EL CODIGO SOLO AGREGUE ESTO Y LISTO
Private Sub Command1_Click()
Dim vic As String
vic = Right(CStr(Format(Text1.Text, “$#,##0.#0;($#,##0)”)), 2)
Text2.Text = “(” & Num2Text(Val(Text1.Text)) & ” PESOS ” & vic & “/100″ & ” MN)”
End Sub
Eso… que bueno que les sirva.
Convertir nros a letras: Por favor si pueden considerar que el que pregunta, no sabe nada, podrian explicarlo paso a paso como se haria en un formulario(facturacion)de access por ejemplo, que a medida que vaya cambiando el valor de la factura, cambie la conversion..gracias.
Muy bueno el código. Gracias
Se me ocurrió otra forma de hacer lo de los decimales, redondea si d tiene más de dos decimales.
Dim d As Double = 123.30
Dim i As Integer = Math.Floor(d)
Dim r As Integer = CInt((d – i) * 100)
rtbTexto.Text = Num2Text(i) & ” CON ” & Num2Text(r) & ” CENTIMOS”
El codigo es genial .. pero yo tuve problemas al tratar de convertir numeros pequeños con decimales (ejem:23.23).. como yo lo solucione es que debajo de esta linea
Public Function Num2Text(ByVal value As Double) As String
Puse
value=int(value)
Por lo demas esta muy bien pensado el codigo.
Se que es poco probable que alguien facture cantidades pequeñas, pero creo que con esto queda completo.
Saludos
hola.
primero agradecer por el codigo esta excelente
solo un detalle me serviria un monton si al final saliera “PESOS”
pero realmente nose como hacerlo
te agradeceria si me lo pudieras explicar
saludos
y gracias
Mil gracias, funciona de maravilla y me saco de una emergencia.
Hola muchísimas gracias por el código y todos los tips!.. son Cheverisimos!.. Aqúí les dejo un ejemplo de como lo arme!!.. 🙂
Private Sub txtmon_LostFocus()
Dim sValor As String, siValor As Single
Dim i, r As Single
sValor = txtmon
txtmon = Val(Replace(sValor, “,”, “.”))
i = Int(Val(txtmon))
r = CInt((txtmon – i) * 100)
Num2Text (Val(txtmon))
If r > 0 Then
txtmonl = txtmonl.Text & ” CON ” + Num2Text(r) + ” CENTIMOS”
End If
txtmon = Format(txtmon, “currency”)
End Sub
Public Function Num2Text(ByVal value As Double) As String
value = Int(value)
Select Case value
Case 0: Num2Text = “CERO”
Case 1: Num2Text = “UN”
Case 2: Num2Text = “DOS”
Case 3: Num2Text = “TRES”
Case 4: Num2Text = “CUATRO”
Case 5: Num2Text = “CINCO”
Case 6: Num2Text = “SEIS”
Case 7: Num2Text = “SIETE”
Case 8: Num2Text = “OCHO”
Case 9: Num2Text = “NUEVE”
Case 10: Num2Text = “DIEZ”
Case 11: Num2Text = “ONCE”
Case 12: Num2Text = “DOCE”
Case 13: Num2Text = “TRECE”
Case 14: Num2Text = “CATORCE”
Case 15: Num2Text = “QUINCE”
Case Is < 20: Num2Text = "DIECI" & Num2Text(value - 10) Case 20: Num2Text = "VEINTE" Case Is < 30: Num2Text = "VEINTI" & Num2Text(value - 20) Case 30: Num2Text = "TREINTA" Case 40: Num2Text = "CUARENTA" Case 50: Num2Text = "CINCUENTA" Case 60: Num2Text = "SESENTA" Case 70: Num2Text = "SETENTA" Case 80: Num2Text = "OCHENTA" Case 90: Num2Text = "NOVENTA" Case Is < 100: Num2Text = Num2Text(Int(value \ 10) * 10) & " Y " & Num2Text(value Mod 10) Case 100: Num2Text = "CIEN" Case Is < 200: Num2Text = "CIENTO " & Num2Text(value - 100) Case 200, 300, 400, 600, 800: Num2Text = Num2Text(Int(value \ 100)) & "CIENTOS" Case 500: Num2Text = "QUINIENTOS" Case 700: Num2Text = "SETECIENTOS" Case 900: Num2Text = "NOVECIENTOS" Case Is < 1000: Num2Text = Num2Text(Int(value \ 100) * 100) & " " & Num2Text(value Mod 100) Case 1000: Num2Text = "MIL" Case Is < 2000: Num2Text = "MIL " & Num2Text(value Mod 1000) Case Is < 1000000: Num2Text = Num2Text(Int(value \ 1000)) & " MIL" If value Mod 1000 Then Num2Text = Num2Text & " " & Num2Text(value Mod 1000) Case 1000000: Num2Text = "UN MILLON" Case Is < 2000000: Num2Text = "UN MILLON " & Num2Text(value Mod 1000000) Case Is < 1000000000000#: Num2Text = Num2Text(Int(value / 1000000)) & " MILLONES " If (value - Int(value / 1000000) * 1000000) Then Num2Text = Num2Text & " " & Num2Text(value - Int(value / 1000000) * 1000000) Case 1000000000000#: Num2Text = "UN BILLON" Case Is < 2000000000000#: Num2Text = "UN BILLON " & Num2Text(value - Int(value / 1000000000000#) * 1000000000000#) Case Else: Num2Text = Num2Text(Int(value / 1000000000000#)) & " BILLONES" If (value - Int(value / 1000000000000#) * 1000000000000#) Then Num2Text = Num2Text & " " & Num2Text(value - Int(value / 1000000000000#) * 1000000000000#) End Select If value = 1 Then txtmonl = Num2Text + " BOLÍVAR" Else txtmonl = Num2Text + " BOLÍVARES" End If End Function ..::Fino verdad??::..
gracias me sirvio bastante el codigo
Alguien tiene el codigo ya convertido para C#
Mucha gracias por el codigo, me acaba de sacar de un apuro.
Habra algo asi pero para ASP (No ASP.Net)… he buscado varias soluciones pero olo he encontrado en javascript
coo ago para que salga la palabra pesos al final
y en el 1000000
un millo DE PESOS
Lo felicito su codigo es muy bueno,solo que me marca un error diciendome que el valor no corresponde a los indices de la matriz ,a que se debera eso
¡¡¡ ESPECTACULAR !!!, y no exagero. Busqué y busqué, encontré una docena de funciones, todas larguísimas y dificiles de implementar. Buscaba algo como esto y lo encontré, gracias. Saludos desde Concepción, Chile
hola, soy meny de chihuahua mexico y keria ver si me podrias hechar la mano en un programa igual a estos pero tengo las variables declaradas de:
dim unidad, decena, centena , num as interger
num = : cint (textbox1.text)
label2.visible = true
etc. etc
y kiero ver kien me puede ayudar a declarar las variables 11, 12,13, 14 y encadenarla en el case declarado en la decena = 1
El codigo funciona prefectamente. Para los que utilizan Visual basic 6.0 y quieren transformar a letras los decimales tambien aqui les mando esta parte:
Public Function Letras(Valor As Double) As String
Dim Largo As Integer
Dim Decimales As Double, strDecimal As String
Largo = Len(CStr(Format(CDbl(Valor), “#,###.00”)))
Decimales = Mid(CStr(Format(CDbl(Valor), “#,###.00″)), Largo – 2)
strDecimal = Mid(CStr(Decimales), 3, 2)
Valor = Valor – Decimales
Letras = Num2Text(Valor) & ” BOLIVARES CON ” & Num2Text(Val(strDecimal)) & ” CENTIMOS.”
end sub
Este Codigo es espectacular, MIL FELICIDADES al programador, quiero hacer este pequeño aporte, porque tuve problemas con numeros del tipo nnnn.0n
y ademas porque normalmente nuestros numeros se encuentran en un textbox
Public Function Convertir(ByVal Numero As String) As String
Dim NumDec As Single
Dim NumEnt As Double
Dim Decimales As Integer
Dim Deci As String
NumDec = Math.Round(CSng(Numero), 2)
NumEnt = Math.Truncate(NumDec)
Decimales = CInt((NumDec – NumEnt) * 100)
Deci = ” ” & Right(“00” & CStr(Decimales), 2) & “/100”
Convertir = Num2Text(NumEnt) & Deci
End Function
Saludos a todos
Excelente, me funciono de maravillas
Muchas Graciaas a todos; el codigo esta de puta madre….. Me an ayudado un culo; muchas gracias; cualkier cosa en la cual yo pueda ser util pasenme la vocina.
ATT. MACURO
Esta Perfecto y lo de los decimales lo solucione de esta manera grax por la ayuda que nos brindan a los que sabemos muy poco
Private Sub Convierte_Click()
Largo = Len(CStr(Format(CDbl(Value), “#,###.00”)))
Decimales = Mid(CStr(Format(CDbl(Value), “#,###.00”)), Largo – 2)
Largo2 = Len(CStr(Format(CDbl(Decimales), “#,###.00″)))
text1.Text = Num2Text(Value – Decimales) & ” PESOS ” & Mid(Decimales, Largo2) & “/100″ & ” M.N. ”
End Sub
como convertir numeros a romanos hasta 100000000
antes que nada te mando un saludo enorme y tengo el mismo problema que muchos, aparte de que soy principiante. te solicito tu ayuda ya que estoy escribiendo la instruccion en visual basic en excel pero no se como la hago funcionar, que debo de hacer.
si funciona desde el programa que estoy utilizando?
orientame por favor.
gracias de nuevo.
mi email es rubisestrada@hotmail.com
esta joda no sirve para nada que proqueriaaaaaaaa
Excelente, tenia la misma idea…pero encontré esto primero jaja
GRACIAS VARGAS ME SACASTE DE UN APURO GRACIAS 🙂
necesito saber como convertir numeros a letras y en pesos, pero tengo un problema, no se mucho computacion si me lo pudieran decir paso a paso
esta codificacion esta buenisima, mi pregunta es como la utilizo. Porque mi resultado en numeros saldra en una etiqueta (label 16).
Que prosigue
Me sirvio mucho el codigo, lo modifique un poco para mi uso en Perú, quiza les ayude el codigo completo que arme gracias a ustedes…
Saludos
ejemplo:
12345.67
DOCE MIL TRESCIENTOS CUARENTA Y CINCO CON 00/100 NUEVOS SOLES
Código:
Public Function Letras(Valor As Double) As String
Dim Largo As Integer
Dim Decimales As Double, strDecimal As String
Largo = Len(CStr(Format(CDbl(Valor), “#,###.00”)))
Decimales = Mid(CStr(Format(CDbl(Valor), “#,###.00”)), Largo – 2)
Select Case Decimales
Case 0: strDecimal = “00”
Case 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9: strDecimal = (Mid(CStr(Decimales), 3, 2)) * 10
Case Is < 100: strDecimal = Mid(CStr(Decimales), 3, 2) End Select Valor = Valor - Decimales Letras = Num2Text(Valor) & " CON " & strDecimal & "/100 NUEVOS SOLES" End Function Public Function Num2Text(ByVal value As Double) As String Select Case Int(value) Case 0: Num2Text = "CERO" Case 1: Num2Text = "UNO" Case 2: Num2Text = "DOS" Case 3: Num2Text = "TRES" Case 4: Num2Text = "CUATRO" Case 5: Num2Text = "CINCO" Case 6: Num2Text = "SEIS" Case 7: Num2Text = "SIETE" Case 8: Num2Text = "OCHO" Case 9: Num2Text = "NUEVE" Case 10: Num2Text = "DIEZ" Case 11: Num2Text = "ONCE" Case 12: Num2Text = "DOCE" Case 13: Num2Text = "TRECE" Case 14: Num2Text = "CATORCE" Case 15: Num2Text = "QUINCE" Case Is < 20: Num2Text = "DIECI" & Num2Text(value - 10) Case 20: Num2Text = "VEINTE" Case Is < 30: Num2Text = "VEINTI" & Num2Text(value - 20) Case 30: Num2Text = "TREINTA" Case 40: Num2Text = "CUARENTA" Case 50: Num2Text = "CINCUENTA" Case 60: Num2Text = "SESENTA" Case 70: Num2Text = "SETENTA" Case 80: Num2Text = "OCHENTA" Case 90: Num2Text = "NOVENTA" Case Is < 100: Num2Text = Num2Text(Int(value \ 10) * 10) & " Y " & Num2Text(value Mod 10) Case 100: Num2Text = "CIEN" Case Is < 200: Num2Text = "CIENTO " & Num2Text(value - 100) Case 200, 300, 400, 600, 800: Num2Text = Num2Text(Int(value \ 100)) & "CIENTOS" Case 500: Num2Text = "QUINIENTOS" Case 700: Num2Text = "SETECIENTOS" Case 900: Num2Text = "NOVECIENTOS" Case Is < 1000: Num2Text = Num2Text(Int(value \ 100) * 100) & " " & Num2Text(value Mod 100) Case 1000: Num2Text = "MIL" Case Is < 2000: Num2Text = "MIL " & Num2Text(value Mod 1000) Case Is < 1000000: Num2Text = Num2Text(Int(value \ 1000)) & " MIL" If value Mod 1000 Then Num2Text = Num2Text & " " & Num2Text(value Mod 1000) Case 1000000: Num2Text = "UN MILLON" Case Is < 2000000: Num2Text = "UN MILLON " & Num2Text(value Mod 1000000) Case Is < 1000000000000#: Num2Text = Num2Text(Int(value / 1000000)) & " MILLONES " If (value - Int(value / 1000000) * 1000000) Then Num2Text = Num2Text & " " & Num2Text(value - Int(value / 1000000) * 1000000) Case 1000000000000#: Num2Text = "UN BILLON" Case Is < 2000000000000#: Num2Text = "UN BILLON " & Num2Text(value - Int(value / 1000000000000#) * 1000000000000#) Case Else: Num2Text = Num2Text(Int(value / 1000000000000#)) & " BILLONES" If (value - Int(value / 1000000000000#) * 1000000000000#) Then Num2Text = Num2Text & " " & Num2Text(value - Int(value / 1000000000000#) * 1000000000000#) End Select End Function
como aplico el codigo., ya que mi resultado en numeros sale en label 16 y quiero que la conversion el letras salga en el textbox10
como aplico el codigo., ya que mi resultado en numeros sale en label 16 y quiero que la conversion el letras salga en el textbox10
sabrás como pasar este código a c++, con una entrada n del numero y que además sea flotante, hasta 3 decimales
excelente codigo me ha servido muchisiiiimo gracias!!
Gracias, por el código me ha sido muy útil, en algun momento si llegaran a requerir código para CRM de MS, en mi blog encontraran una variedad interesante de TIPS.
Saludos
MUUCHAS GRACIAS, Johnny…. Me ha servido muchísimo. Por lo demás q se tiene q programar para las monedas de los distintos países sólo basta con algunas aportaciones q han puesto (yo lo estoy trabajando para México y Venezuela). Pero lo que tú hiciste está excelente. Muchas gracias
muy bueno me salvaste la vida por que tenia una tarea de estas y la oavia buscado por todas partes y encontraba pero era mas raro de entenderle gracias
Muchas gracias!!! Jhonny, esta muy bueno el código me sirvio mucho.
Buenisimo Gracias por tu aporte me ayudo un monton GRACIAS!!!!!!!!!!!!!!!!! *)
eres un perrillo!!!
esta chevere tu prog…
haces un paronon guey.
serra!!!!
Lo necesitaba en c#, así que hice la traducción, les dejo la clase:
using System;
using System.Collections.Generic;
using System.Text;
namespace Conversiones
{
class Conv
{
public string enletras(string num)
{
string res, dec = “”;
Int64 entero;
int decimales;
double nro;
try
{
nro = Convert.ToDouble(num);
}
catch
{
return “”;
}
entero = Convert.ToInt64(Math.Truncate(nro));
decimales = Convert.ToInt32(Math.Round((nro – entero) * 100, 2));
if (decimales > 0)
{
dec = ” CON ” + decimales.ToString() + “/100”;
}
res = toText(Convert.ToDouble(entero)) + dec;
return res;
}
private string toText(double value)
{
string Num2Text = “”;
value = Math.Truncate(value);
if (value == 0) Num2Text = “CERO”;
else if (value == 1) Num2Text = “UNO”;
else if (value == 2) Num2Text = “DOS”;
else if (value == 3) Num2Text = “TRES”;
else if (value == 4) Num2Text = “CUATRO”;
else if (value == 5) Num2Text = “CINCO”;
else if (value == 6) Num2Text = “SEIS”;
else if (value == 7) Num2Text = “SIETE”;
else if (value == 8) Num2Text = “OCHO”;
else if (value == 9) Num2Text = “NUEVE”;
else if (value == 10) Num2Text = “DIEZ”;
else if (value == 11) Num2Text = “ONCE”;
else if (value == 12) Num2Text = “DOCE”;
else if (value == 13) Num2Text = “TRECE”;
else if (value == 14) Num2Text = “CATORCE”;
else if (value == 15) Num2Text = “QUINCE”;
else if (value < 20) Num2Text = "DIECI" + toText(value - 10); else if (value == 20) Num2Text = "VEINTE"; else if (value < 30) Num2Text = "VEINTI" + toText(value - 20); else if (value == 30) Num2Text = "TREINTA"; else if (value == 40) Num2Text = "CUARENTA"; else if (value == 50) Num2Text = "CINCUENTA"; else if (value == 60) Num2Text = "SESENTA"; else if (value == 70) Num2Text = "SETENTA"; else if (value == 80) Num2Text = "OCHENTA"; else if (value == 90) Num2Text = "NOVENTA"; else if (value < 100) Num2Text = toText(Math.Truncate(value / 10) * 10) + " Y " + toText(value % 10); else if (value == 100) Num2Text = "CIEN"; else if (value < 200) Num2Text = "CIENTO " + toText(value - 100); else if ((value == 200) || (value == 300) || (value == 400) || (value == 600) || (value == 800)) Num2Text = toText(Math.Truncate(value / 100)) + "CIENTOS"; else if (value == 500) Num2Text = "QUINIENTOS"; else if (value == 700) Num2Text = "SETECIENTOS"; else if (value == 900) Num2Text = "NOVECIENTOS"; else if (value < 1000) Num2Text = toText(Math.Truncate(value / 100) * 100) + " " + toText(value % 100); else if (value == 1000) Num2Text = "MIL"; else if (value < 2000) Num2Text = "MIL " + toText(value % 1000); else if (value < 1000000) { Num2Text = toText(Math.Truncate(value / 1000)) + " MIL"; if ((value % 1000) > 0) Num2Text = Num2Text + ” ” + toText(value % 1000);
}
else if (value == 1000000) Num2Text = “UN MILLON”;
else if (value < 2000000) Num2Text = "UN MILLON " + toText(value % 1000000); else if (value < 1000000000000) { Num2Text = toText(Math.Truncate(value / 1000000)) + " MILLONES "; if ((value - Math.Truncate(value / 1000000) * 1000000) > 0) Num2Text = Num2Text + ” ” + toText(value – Math.Truncate(value / 1000000) * 1000000);
}
else if (value == 1000000000000) Num2Text = “UN BILLON”;
else if (value < 2000000000000) Num2Text = "UN BILLON " + toText(value - Math.Truncate(value / 1000000000000) * 1000000000000); else { Num2Text = toText(Math.Truncate(value / 1000000000000)) + " BILLONES"; if ((value - Math.Truncate(value / 1000000000000) * 1000000000000) > 0) Num2Text = Num2Text + ” ” + toText(value – Math.Truncate(value / 1000000000000) * 1000000000000);
}
return Num2Text;
}
}
}
Gracias Gerardo… subiré tu código en C# sino te molesta… si es así… avisame y lo quito.
Un abrazo!
Buenas, soy nuevo en el manejo de base de datos, pero necesito saber como en una hoja de excel puedo crear una macros parea convertir numeros a letras en pesos.
Exelente función, me acaba de ahorrar un día de trabajo… Para quien quiera que funcione con decimales aquí les dejo un recurso que pude crear:
Dim i, pos As Short
Dim Ent, Dec As Single
For i = 1 To Len(txtNumero.Text)
If Mid(txtNumero.Text, i, 1) = “.” Then
pos = i
Ent = Mid(txtNumero.Text, 1, i – 1)
Dec = Mid(txtNumero.Text, i + 1, 2)
End If
Next
lblTexto.Text = Num2Text(Ent) + ” con ” + Num2Text(Dec) + “Decimales”
Obviamente: txtNumero es el control en el cual se ingresa el número a convertir y lblTexto es el control donde se recibe el valor en letras.
Mil gracias
Muchas Gracias por sus aportes, sirvio de mucho.
quiero convertir el numero 255 a letras
Esta función la utilizo para convertir nros. a textos en ASP. Espero que les sirva.
<% 'funcion para convertir números a letras ''nro=request.querystring("a") '-*-*-*-*-*-*-*-*-*-*-*-*-*-*-' '-*-*-*-*-*-*-*-*-*-*-*-*-*-*-' moneda=" PESOS" Function Letras(NUMERO,DIVISIONX) AUX1 = NUMERO DIVISION=DIVISIONX CADENA = " " Do While DIVISION > 0
Select Case DIVISION
Case 100
If Int(AUX1 / DIVISION) >= 1 Then
If Int(AUX1 / DIVISION) <> AUX1 / DIVISION And Int(AUX1 / DIVISION) = 1 Then
CADENA = CADENA + “CIENTO”
Else
select case Int(AUX1 / DIVISION)
case 1
cadena= cadena + “CIEN”
case 2
cadena= cadena + “DOSCIENTOS”
case 3
cadena= cadena + “TRESCIENTOS”
case 4
cadena= cadena + “CUATROCIENTOS”
case 5
cadena= cadena + “QUINIENTOS”
case 6
cadena= cadena + “SEISCIENTOS”
case 7
cadena= cadena + “SETECIENTOS”
case 8
cadena= cadena + “OCHOCIENTOS”
case 9
cadena= cadena + “NOVECIENTOS”
END SELECT
End If
CADENA = CADENA + ” ”
End If
Case 10
If Int(AUX1 / DIVISION) >= 1 Then
If Int(AUX1 / DIVISION) <> AUX1 / DIVISION Then
If AUX1 <= 15 Then select case AUX1 -10 case 1 cadena= cadena + "ONCE" case 2 cadena= cadena + "DOCE" case 3 cadena= cadena + "TRECE" case 4 cadena= cadena + "CATORCE" case 5 cadena= cadena + "QUINCE" END SELECT Exit Do Else select case Int(AUX1 / DIVISION) case 1 cadena= cadena + "DIECI" case 2 cadena= cadena + "VEINTI" case 3 cadena= cadena + "TREINTA Y " case 4 cadena= cadena + "CUARENTA Y " case 5 cadena= cadena + "CINCUENTA Y " case 6 cadena= cadena + "SESENTA Y " case 7 cadena= cadena + "SETENTA Y " case 8 cadena= cadena + "OCHENTA Y " case 9 cadena= cadena + "NOVENTA Y " END SELECT End If Else select case Int(AUX1 / DIVISION) case 1 cadena= cadena + "DIEZ" case 2 cadena= cadena + "VEINTE" case 3 cadena= cadena + "TREINTA" case 4 cadena= cadena + "CUARENTA" case 5 cadena= cadena + "CINCUENTA" case 6 cadena= cadena + "SESENTA" case 7 cadena= cadena + "SETENTA" case 8 cadena= cadena + "OCHENTA" case 9 cadena= cadena + "NOVENTA" END SELECT End If End If Case 1 If AUX1 > 0 Then
select case AUX1
case 1
cadena= cadena + “UN”
case 2
cadena= cadena + “DOS”
case 3
cadena= cadena + “TRES”
case 4
cadena= cadena + “CUATRO”
case 5
cadena= cadena + “CINCO”
case 6
cadena= cadena + “SEIS”
case 7
cadena= cadena + “SIETE”
case 8
cadena= cadena + “OCHO”
case 9
cadena= cadena + “NUEVE”
END SELECT
End If
End Select
AUX1 = AUX1 – (Int(AUX1 / DIVISION) * DIVISION)
DIVISION = Int(DIVISION / 10)
Loop
Letras = CADENA
End Function
‘-*-*-*-*-*-*-*-*-*-*-*-*-*-*-‘
FUNCTION MONTOESCRITO(NRO)
NRO=NRO
ON ERROR RESUME NEXT
SIGNONEGATIVO=””
NEGATIVO=””
FUENTE=””
IF NRO<0 THEN
LENNUMERON=LEN(NRO)
SIGNONEGATIVO="-"
NEGATIVO="MENOS "
NRO=MID(NRO,2,LENNUMERON)
FUENTE="”
END IF
if nro>99999999.99 then
response.write “
Atención!!!
El importe debe ser menor a 99999999.99
”
response.write “NOVENTA Y NUEVE MILLONES NOVECIENTOS NOVENTA Y NUEVE MIL NOVECIENTOS NOVENTA Y NUEVE CON NOVENTA Y NUEVE
”
response.write “
”
response.write “
Creado por Eduardo J. M. Nuñez Feltan – ©”&year(date())&”
”
response.end
end if
MONEDA=MONEDA
if moneda=” DOLARES” THEN
SIGNO=”U$S”
ELSE
SIGNO=”$”
END IF
lennumero=len(nro)
punto=instr(nro,”.”)
if punto=0 then
punto=instr(nro,”,”)
end if
IF LEFT(NRO,1)=”0″ THEN
NUMEROENTERO=”0″
ELSE
”numeroentero=int(nro)
if punto<>0 then
numeroentero=int(mid(nro,1,punto-1))
else
numeroentero=int(nro)
end if
END IF
LONGITUDENTERO=LEN(NUMEROENTERO)
select case LONGITUDENTERO
case 1
”entre=”1-9″
div=1
case 2
”entre=”10-99″
div=10
case 3
”entre=”100-999″
div=100
case 4
”entre=”1000-9999″
DIV1=1
div=1000
MIL=LETRAS(LEFT(NUMEROENTERO,1),DIV1)&” MIL ”
case 5
”entre=”10000-99999″
div1=10
DIV=10000
MIL=LETRAS(LEFT(NUMEROENTERO,2),DIV1)&” MIL ”
case 6
”entre=”100000-99999″
div1=100
DIV=100000
MIL=LETRAS(LEFT(NUMEROENTERO,3),DIV1)&” MIL ”
case 7
”entre=”1000000-9999999″
DIV1=1
div=1000000
MIL=LETRAS(LEFT(NUMEROENTERO,1),DIV1)
IF MIL=” UN” THEN
MIL=MIL&” MILLÓN ”
ELSE
MIL=MIL&” MILLONES ”
END IF
DIV1=100
div=1000
CIENTO=LETRAS(MID(NUMEROENTERO,2,3),DIV1)&” MIL ”
IF CIENTO=” MIL ” THEN
MIL=MIL
ELSE
MIL=MIL&CIENTO
END IF
case 8
”entre=”10000000-99999999″
DIV1=10
div=10000000
MIL=LETRAS(LEFT(NUMEROENTERO,2),DIV1)
IF MIL=” UN” THEN
MIL=MIL&” MILLÓN ”
ELSE
MIL=MIL&” MILLONES ”
END IF
DIV1=100
div=1000
CIENTO=LETRAS(MID(NUMEROENTERO,1,1),DIV1)&” MIL ”
IF CIENTO=” MIL ” THEN
MIL=MIL
ELSE
MIL=MIL&CIENTO
END IF
end select
DIV2=10
if punto<>0 then
CUANTOSCENTAVOS=mid(nro,punto+1,2)
if CUANTOSCENTAVOS=00 then
centavos=0
else
IF LEN(CUANTOSCENTAVOS)=1 THEN
centavos=mid(nro,punto+1,2)&”0″
‘response.write centavos
ELSE
centavos=mid(nro,punto+1,2)
‘response.write centavos
END IF
end if
end if
r=letras(numeroentero,DIV)
”response.write “
”
response.write ““&FUENTE&NEGATIVO
IF MIL=”” AND R=” UN” THEN
IF MONEDA=” DOLARES” THEN
MONEDA=LEFT(MONEDA,6)
ELSE IF MONEDA=” PESOS” THEN
MONEDA=LEFT(MONEDA,5)
END IF
END IF
END IF
MONTOESCRITOX=MIL&r&MONEDA
IF MONTOESCRITOX=” PESOS” OR MONTOESCRITOX=” DOLARES” THEN
MONTOESCRITOX=””
ELSE
RESPONSE.WRITE MONTOESCRITOX
END IF
‘x=letras(centavos,DIV2)
if centavos<>0 then
IF PUNTO<>0 AND X<> ” ” THEN
if montoescritox=”” then
response.write x&” CENTAVOS.”
ELSE
‘response.write ” CON “&x&” CENTAVOS.”
response.write ” con “¢avos&”/100.”
end if
else
‘response.write ” CON “&x&” CENTAVOS.”
response.write ” con “¢avos&”/100.”
END IF
end if
end function
%>
‘//////////////////////////////////////////////////
‘y para llamar a la función utilizo lo siguiente:
‘
‘acumula es el valor numérico que quiero convertir a Texto
‘//////////////////////////////////////////////////
<%sx=montoescrito(acumula) response.write sx%>
‘espero les sea de su agrado.
Saludos desde Campo Viera Miisones, Argentina
y como lo hago alreves?? entrar un valor en palabras.. y que te entregue el valor numerico correspondiente
:/
em todo eso sale mal al ejecutar por k no reconoce
END FUNCTION si saben ese ¿porque? rspondan a este
comentario ……
…jhoel daniel…JDPD
como puedo utilizar el codigo o la funcion en Excel 2003
gracias
Gracias por la función, me salvaste el proyecto!
Saludos!
por fa si pueden enviamenlo a mi correo el cual es nilve_2005@yahoo.es
por fa si pueden envienmelo a mi correo el cual es nilve_2005@hotmail.com
La funcion esta de lujo, a mi tambien me ahorro un dia o hasta mas tiempo en codificar esta funcion que lo mas comun en donde se usan es en la facturaccion y los cheques que los gorrosos contadores piden o administradores
TENGO ELSIGUIENTE PROBLEMA CON CIENTO UNO MIL, DOSCIENTOS UNO MIL
101,000.00 CIENTO UNO MIL 00/100 DOLARES
201,000.00 DOSCIENTOS UNO MIL 00/100 DOLARES
301,000.00 TRESCIENTOS UNO MIL 00/100 DOLARES
401,000.00 CUATROCIENTOS UNO MIL 00/100 DOLARES
COMO PUEDO CORREGIRLO??
Codigo buenisimos gracias solo hay que agregar dos textbox y un boton :
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim d As Double
d = TextBox1.Text
Dim i As Integer = Math.Floor(d)
Dim r As Integer = CInt((d – i) * 100)
TextBox2.Text = “Bolivares” & Num2Text(i) & ” CON ” & Num2Text(r) & ” CENTIMOS”
End Sub
Public Function Num2Text(ByVal value As Double) As String
Select Case value
Case 0 : Num2Text = “CERO”
Case 1 : Num2Text = “UN”
Case 2 : Num2Text = “DOS”
Case 3 : Num2Text = “TRES”
Case 4 : Num2Text = “CUATRO”
Case 5 : Num2Text = “CINCO”
Case 6 : Num2Text = “SEIS”
Case 7 : Num2Text = “SIETE”
Case 8 : Num2Text = “OCHO”
Case 9 : Num2Text = “NUEVE”
Case 10 : Num2Text = “DIEZ”
Case 11 : Num2Text = “ONCE”
Case 12 : Num2Text = “DOCE”
Case 13 : Num2Text = “TRECE”
Case 14 : Num2Text = “CATORCE”
Case 15 : Num2Text = “QUINCE”
Case Is < 20 : Num2Text = "DIECI" & Num2Text(value - 10) Case 20 : Num2Text = "VEINTE" Case Is < 30 : Num2Text = "VEINTI" & Num2Text(value - 20) Case 30 : Num2Text = "TREINTA" Case 40 : Num2Text = "CUARENTA" Case 50 : Num2Text = "CINCUENTA" Case 60 : Num2Text = "SESENTA" Case 70 : Num2Text = "SETENTA" Case 80 : Num2Text = "OCHENTA" Case 90 : Num2Text = "NOVENTA" Case Is < 100 : Num2Text = Num2Text(Int(value \ 10) * 10) & " Y " & Num2Text(value Mod 10) Case 100 : Num2Text = "CIEN" Case Is < 200 : Num2Text = "CIENTO " & Num2Text(value - 100) Case 200, 300, 400, 600, 800 : Num2Text = Num2Text(Int(value \ 100)) & "CIENTOS" Case 500 : Num2Text = "QUINIENTOS" Case 700 : Num2Text = "SETECIENTOS" Case 900 : Num2Text = "NOVECIENTOS" Case Is < 1000 : Num2Text = Num2Text(Int(value \ 100) * 100) & " " & Num2Text(value Mod 100) Case 1000 : Num2Text = "MIL" Case Is < 2000 : Num2Text = "MIL " & Num2Text(value Mod 1000) Case Is < 1000000 : Num2Text = Num2Text(Int(value \ 1000)) & " MIL" If value Mod 1000 Then Num2Text = Num2Text & " " & Num2Text(value Mod 1000) Case 1000000 : Num2Text = "UN MILLON" Case Is < 2000000 : Num2Text = "UN MILLON " & Num2Text(value Mod 1000000) Case Is < 1000000000000.0# : Num2Text = Num2Text(Int(value / 1000000)) & " MILLONES " If (value - Int(value / 1000000) * 1000000) Then Num2Text = Num2Text & " " & Num2Text(value - Int(value / 1000000) * 1000000) Case 1000000000000.0# : Num2Text = "UN BILLON" Case Is < 2000000000000.0# : Num2Text = "UN BILLON " & Num2Text(value - Int(value / 1000000000000.0#) * 1000000000000.0#) Case Else : Num2Text = Num2Text(Int(value / 1000000000000.0#)) & " BILLONES" If (value - Int(value / 1000000000000.0#) * 1000000000000.0#) Then Num2Text = Num2Text & " " & Num2Text(value - Int(value / 1000000000000.0#) * 1000000000000.0#) End Select End Function End Class
hola quisiera saber si pueden ayudarme necesito el mismo codigo que convierte numeros en letras pero para aplicarlo en access, serian tan amable de ayudarme, mil gracias yesidcorrea@gmail.com
como puedo eliminar la parte entera de un numero decimal para poder utilizar solo los decimales
Encontré en esta dirección un código sin tanto error, espero que les sirva
http://www.lawebdelprogramador.com/codigo/enlace.php?idp=1333&id=127
SUPER BIEN EL CODIGO ME SIRVIO MUCHISSIIISIIIMO!!
APARTE FACIL DE ENTENDER!
TNKS!
PORFAVOR NECESITO QUE ALGUIEN ME PUEDA PROPORCIONAR LA FORMA DE CAMBIAR EL COLOR DE CARACTERES Y EL FONDO DE PANTALLA DE DOS USANDO UN CODIGO DESDE EL PROGRAMA DE C++.
en que meto el codigo en cajas d texto o en donde si m pueden ayudar
SOY DE LOS QUE APRENDEN HACIENDO Y NO HE PODIDO HACER QUE EL CODIGO ME FUNCIONE EN ACCESS. AGRADECERIA INMENSAMENTE A QUIEN ME PUEDA COLABORAR, PASO A PASO.
NO SE PORQUÈ PEGO EL CODIGO EN ACCESS Y NO ME FUNCIONA
AYÙDENME, POR FAVOR.
GRACIAS.
luisramirogamboa@hotmail.com
luisramirogamboa@yahoo.com
Hola, este codigo me sirvio muchisimo solo que yo programo en c# y lo paso todo a este lenguaje, lo pongo aqui pero tambien les dejo un enlace con el programa para poder ver como funciona, esta en visual c# 2005.
private string Numero_A_Letra(double valor)
{
switch ((int)valor)
{
case 0: retun = “”; break;
case 1: retun = “UN”; break;
case 2: retun = “DOS”; break;
case 3: retun = “TRES”; break;
case 4: retun = “CUATRO”; break;
case 5: retun = “CINCO”; break;
case 6: retun = “SEIS”; break;
case 7: retun = “SIETE”; break;
case 8: retun = “OCHO”; break;
case 9: retun = “NUEVE”; break;
case 10: retun = “DIEZ”; break;
case 11: retun = “ONCE”; break;
case 12: retun = “DOCE”; break;
case 13: retun = “TRECE”; break;
case 14: retun = “CATORCE”; break;
case 15: retun = “QUINCE”; break;
case 16: case 17: case 18: case 19: retun = “DIECI” + Numero_A_Letra(valor – 10); break;
case 20: retun = “VEINTE”; break;
case 21: case 22: case 23: case 24: case 25: case 26: case 27: case 28: case 29: retun = “VEINTI” + Numero_A_Letra(valor – 20); break;
case 30: retun = “TREINTA”; break;
case 40: retun = “CUARENTA”; break;
case 50: retun = “CINCUENTA”; break;
case 60: retun = “SESENTA”; break;
case 70: retun = “SETENTA”; break;
case 80: retun = “OCHENTA”; break;
case 90: retun = “NOVENTA”; break;
case 100: retun = “CIEN”; break;
case 200: case 300: case 400: case 600: case 800: retun = Numero_A_Letra((int)valor / 100) + “CIENTOS”; break;
case 500: retun = “QUINIENTOS”; break;
case 700: retun = “SETECIENTOS”; break;
case 900: retun = “NOVECIENTOS”; break;
case 1000: retun = “MIL”; break;
case 1000000: retun = “UN MILLON DE”; break;
default:
if (valor < 100) { retun = Numero_A_Letra((int)(valor / 10) * 10) + " Y " + Numero_A_Letra(valor % 10); } else if (valor < 200) { retun = "CIENTO " + Numero_A_Letra(valor - 100); } else if (valor < 1000) { retun = Numero_A_Letra((int)(valor / 100) * 100) + " " + Numero_A_Letra(valor % 100); } else if (valor < 2000) { retun = "MIL " + Numero_A_Letra(valor % 1000); } else if (valor < 1000000) { retun = Numero_A_Letra((int)valor / 1000) + " MIL"; if (valor % 1000 < 1000) { retun = retun + " " + Numero_A_Letra(valor % 1000); } } else if (valor < 2000000) { retun = "UN MILLON " + Numero_A_Letra(valor % 1000000); } else if (valor < 1000000000000.0) { retun = Numero_A_Letra((int)valor / 1000000) + " MILLONES "; if ((valor - (int)(valor / 1000000) * 1000000) < 1000000 && (valor - (int)(valor / 1000000) * 1000000) != 0) { retun = retun + Numero_A_Letra(valor - (int)(valor / 1000000) * 1000000); } else { retun = retun + "DE"; } } else if (valor == 1000000000000.0) { retun = "UN BILLON DE"; } else if (valor < 2000000000000.0) { retun = "UN BILLON " + Numero_A_Letra(valor - (int)(valor / 1000000000000.0) * 1000000000000.0); } else { retun = Numero_A_Letra((int)(valor / 1000000000000.0)) + " BILLONES "; if (valor - (int)(valor / 1000000000000.0) * 1000000000000.0 < 1000000000000.0 && valor - (int)(valor / 1000000000000.0) * 1000000000000.0 != 0) { retun = retun + Numero_A_Letra(valor - (int)(valor / 1000000000000.0) * 1000000000000.0); } else { retun = retun + "DE"; } } break; } return retun; } private string Num2Letra(string numero, string moneda, bool nacional) { string nacion = ")"; string decimales = "00"; if (nacional) { nacion = " M.N.)"; } else { nacion = " USD)"; } if (numero.Contains(".")) if (numero.Substring(numero.IndexOf(".") + 1).Length > 1) { decimales = numero.Substring(numero.IndexOf(“.”) + 1, 2); }
else { decimales = numero.Substring(numero.IndexOf(“.”) + 1) + “0”; }
string valor = “(” + Numero_A_Letra(Convert.ToDouble(numero)).Trim() + ” ” + moneda + ” ” + decimales + “/100”;
return valor + nacion;
}
AQUI ESTA EL ENLACE:
http://sipro.diinoweb.com/files/Mis%20Archivos%20de%20Trabajo/NumALetras.zip
Exelente Jhonny… lo implemente en Excel 2002 y me funcionó de maravilla … solo modifique un poco lo de “EleAEse” agregando esto al final de tu código para que funcione en la hoja de calculo como una funcion del usuario… salu2
Public Function NumeroATexto(ByVal d As Double) As String
If d – Int(d) Then
Lentero = Num2Text(Int(d))
Ldec = Num2Text(Mid(d – Int(d), 3, 2))
NumeroATexto = Num2Text(Int(d)) & ” PESOS CON ” & Num2Text(Mid(d – Int(d), 3, 2)) & ” CENTAVOS”
Else
NumeroATexto = Num2Text(Int(d)) & ” PESOS”
End If
End Function
ESPERO LES SIRVA.. ME AYUDARON UN GUEVO… GRACIAS!!!
Muy bueno tu codigo Sandro Patricio me sirvio mucho… me ahorraste quemarme el cerebro Gracias
Muchas gracias por compartir código en C# y para Excel.
HOLA, hace un par de dias necesite ese código para una pequeña aplicación de impresión de cheques, pero no encontre algo adaptable y sin errores, así que devuelta a la maravillosa programación. Decidi escribirlo con muy buenos resultados. En cuanto a mi código es más extenso por su estructura.
La aplicación la hice en ACCES 2003 No se como subirla
pero aqui va el CODE y ustedes me cuentan.
Pueden ponerlo en el evento “despues de actualizar” de un cuadro de texto. Lo tengo limitado a 999’999.999
pero podran acomodarlo a su necesidad facilmente. Peguenlo en un editor para que puedan verlo bien.
‘CONVERSION DE UN NUMERO A SU CORRESPONDIENTE VALOR EN LETRAS
‘BY Leo buzondeleo@yahoo.com
‘Iniciado 12 de Marzo de 2008
‘Esta version funciona OK, pero podra ser más compacta en un futuro (por aquello de la critica).
‘Manejo sutilmente las decenas, centenas etc. y el cero es decir sin matarme la cabeza.
‘Tengo pendiente los decimales por que no los uso, pero lo completare dentro de poco.
‘Facilmente podra ajustarse a otras monedas.
Private Sub Valor_AfterUpdate()
Dim ValATexto, TextoAux, Siguiente, PostSiguiente, Scan As String
Dim LongValor, I, J, K, Posicion As Integer
Dim Redondo As Boolean
‘Aqui comienza todo: El numero a convertir en letras es capturado en Valor (Cuadro de texto) y _
se refleja en otro cuadro de texto (LaSumaDe).
‘***WARNING*** Utilicen una regla de validación para evitar desbordamientos, yo lo hice en el formulario pueden también con codigo.
ValATexto = LTrim(Str(Valor)) ‘Convierte el valor a texto y elimina el espacio a la izquierda
LongValor = Len(ValATexto) ‘Mide la longitud del texto en caracteres
For I = 1 To LongValor
‘Detecta el número siguiente al que se sensa en el primer “Select Case”
If LongValor > 1 Then Siguiente = Mid(ValATexto, I + 1, 1)
‘Detecta el segundo número siguiente al que se sensa en el primer “Select Case”
If LongValor > 2 Then PostSiguiente = Mid(ValATexto, I + 2, 1)
Posicion = LongValor + 1 – I ‘Sensor de posición
Select Case Mid(ValATexto, I, 1) ‘Sensor de numero
‘ 1
Case “1” ‘Si encuentra por ejemplo un “1” procedera a determinar _
la posicion dentro de la cantidad para asignarle su valor en letras
Select Case Posicion ‘El bloque de seleccion para el “1” es más largo que los demás por 11,12,13…19
Case 1, 7
If Posicion = 7 And LongValor > 7 Then
TextoAux = TextoAux + “UN MILLONES ” ‘Ej: 21’8–.—
ElseIf Posicion = 7 Then
TextoAux = TextoAux + “UN MILLON ” ‘Ej: 1’8–.—
Else
TextoAux = TextoAux + “UN ” ‘Ej: 21
End If
Case 2, 5, 8
If Siguiente = “0” Then
TextoAux = TextoAux + “DIEZ ”
ElseIf Siguiente = “1” Then
TextoAux = TextoAux + “ONCE ”
I = I + 1 ‘Salta el sensor una posición para evitar Ej: 12 = “DOCE DOS”
ElseIf Siguiente = “2” Then
TextoAux = TextoAux + “DOCE ”
I = I + 1
ElseIf Siguiente = “3” Then
TextoAux = TextoAux + “TRECE ”
I = I + 1
ElseIf Siguiente = “4” Then
TextoAux = TextoAux + “CATORCE ”
I = I + 1
ElseIf Siguiente = “5” Then
TextoAux = TextoAux + “QUINCE ”
I = I + 1
ElseIf Siguiente = “6” Then
TextoAux = TextoAux + “DIECISEIS ”
I = I + 1
ElseIf Siguiente = “7” Then
TextoAux = TextoAux + “DIECISIETE ”
I = I + 1
ElseIf Siguiente = “8” Then
TextoAux = TextoAux + “DIECIOCHO ”
I = I + 1
ElseIf Siguiente = “9” Then
TextoAux = TextoAux + “DIECINUEVE ”
I = I + 1
End If
If Posicion = 5 Then TextoAux = TextoAux + “MIL ”
If Posicion = 8 Then TextoAux = TextoAux + “MILLONES ”
Case 3, 6, 9
If Siguiente = “0” And PostSiguiente = “0” Then
TextoAux = TextoAux + “CIEN ”
If Posicion = 6 Then TextoAux = TextoAux + “MIL ”
If Posicion = 9 Then TextoAux = TextoAux + “MILLONES ”
Else
TextoAux = TextoAux + “CIENTO ”
End If
Case 4
TextoAux = TextoAux + “MIL ”
End Select
‘ 2
Case “2”
Select Case Posicion
Case 1, 7
If Posicion = 7 Then
TextoAux = TextoAux + “DOS MILLONES ”
Else
TextoAux = TextoAux + “DOS ”
End If
Case 2, 5, 8
If Siguiente = “0” Then
TextoAux = TextoAux + “VEINTE ”
If Posicion = 5 Then TextoAux = TextoAux + “MIL ”
If Posicion = 8 Then TextoAux = TextoAux + “MILLONES ”
Else
TextoAux = TextoAux + “VEINTI ”
End If
Case 3, 6, 9
If Siguiente = “0” And PostSiguiente = “0” Then
TextoAux = TextoAux + “DOCIENTOS ”
If Posicion = 6 Then TextoAux = TextoAux + “MIL ”
If Posicion = 9 Then TextoAux = TextoAux + “MILLONES ”
Else
TextoAux = TextoAux + “DOCIENTOS ”
End If
Case 4
TextoAux = TextoAux + “DOS MIL ”
End Select
‘ 3 A partir de aquí no cambia nada
Case “3”
Select Case Posicion
Case 1, 7
If Posicion = 7 Then
TextoAux = TextoAux + “TRES MILLONES ”
Else
TextoAux = TextoAux + “TRES ”
End If
Case 2, 5, 8
If Siguiente = “0” Then
TextoAux = TextoAux + “TREINTA ”
If Posicion = 5 Then TextoAux = TextoAux + “MIL ”
If Posicion = 8 Then TextoAux = TextoAux + “MILLONES ”
Else
TextoAux = TextoAux + “TREINTA Y ”
End If
Case 3, 6, 9
If Siguiente = “0” And PostSiguiente = “0” Then
TextoAux = TextoAux + “TRECIENTOS ”
If Posicion = 6 Then TextoAux = TextoAux + “MIL ”
If Posicion = 9 Then TextoAux = TextoAux + “MILLONES ”
Else
TextoAux = TextoAux + “TRECIENTOS ”
End If
Case 4
TextoAux = TextoAux + “TRES MIL ”
End Select
‘ 4
Case “4”
Select Case Posicion
Case 1, 7
If Posicion = 7 Then
TextoAux = TextoAux + “CUATRO MILLONES ”
Else
TextoAux = TextoAux + “CUATRO ”
End If
Case 2, 5, 8
If Siguiente = “0” Then
TextoAux = TextoAux + “CUARENTA ”
If Posicion = 5 Then TextoAux = TextoAux + “MIL ”
If Posicion = 8 Then TextoAux = TextoAux + “MILLONES ”
Else
TextoAux = TextoAux + “CUARENTA Y ”
End If
Case 3, 6, 9
If Siguiente = “0” And PostSiguiente = “0” Then
TextoAux = TextoAux + “CUATROCIENTOS ”
If Posicion = 6 Then TextoAux = TextoAux + “MIL ”
If Posicion = 9 Then TextoAux = TextoAux + “MILLONES ”
Else
TextoAux = TextoAux + “CUATROCIENTOS ”
End If
Case 4
TextoAux = TextoAux + “CUATRO MIL ”
End Select
‘ 5
Case “5”
Select Case Posicion
Case 1, 7
If Posicion = 7 Then
TextoAux = TextoAux + “CINCO MILLONES ”
Else
TextoAux = TextoAux + “CINCO ”
End If
Case 2, 5, 8
If Siguiente = “0” Then
TextoAux = TextoAux + “CINCUENTA ”
If Posicion = 5 Then TextoAux = TextoAux + “MIL ”
If Posicion = 8 Then TextoAux = TextoAux + “MILLONES ”
Else
TextoAux = TextoAux + “CINCUENTA Y ”
End If
Case 3, 6, 9
If Siguiente = “0” And PostSiguiente = “0” Then
TextoAux = TextoAux + “QUINIENTOS ”
If Posicion = 6 Then TextoAux = TextoAux + “MIL ”
If Posicion = 9 Then TextoAux = TextoAux + “MILLONES ”
Else
TextoAux = TextoAux + “QUINIENTOS ”
End If
Case 4
TextoAux = TextoAux + “CINCO MIL ”
End Select
‘ 6
Case “6”
Select Case Posicion
Case 1, 7
If Posicion = 7 Then
TextoAux = TextoAux + “SEIS MILLONES ”
Else
TextoAux = TextoAux + “SEIS ”
End If
Case 2, 5, 8
If Siguiente = “0” Then
TextoAux = TextoAux + “SESENTA ”
If Posicion = 5 Then TextoAux = TextoAux + “MIL ”
If Posicion = 8 Then TextoAux = TextoAux + “MILLONES ”
Else
TextoAux = TextoAux + “SESENTA Y ”
End If
Case 3, 6, 9
If Siguiente = “0” And PostSiguiente = “0” Then
TextoAux = TextoAux + “SEICIENTOS ”
If Posicion = 6 Then TextoAux = TextoAux + “MIL ”
If Posicion = 9 Then TextoAux = TextoAux + “MILLONES ”
Else
TextoAux = TextoAux + “SEICIENTOS ”
End If
Case 4
TextoAux = TextoAux + “SEIS MIL ”
End Select
‘ 7
Case “7”
Select Case Posicion
Case 1, 7
If Posicion = 7 Then
TextoAux = TextoAux + “SIETE MILLONES ”
Else
TextoAux = TextoAux + “SIETE ”
End If
Case 2, 5, 8
If Siguiente = “0” Then
TextoAux = TextoAux + “SETENTA ”
If Posicion = 5 Then TextoAux = TextoAux + “MIL ”
If Posicion = 8 Then TextoAux = TextoAux + “MILLONES ”
Else
TextoAux = TextoAux + “SETENTA Y ”
End If
Case 3, 6, 9
If Siguiente = “0” And PostSiguiente = “0” Then
TextoAux = TextoAux + “SETECIENTOS ”
If Posicion = 6 Then TextoAux = TextoAux + “MIL ”
If Posicion = 9 Then TextoAux = TextoAux + “MILLONES ”
Else
TextoAux = TextoAux + “SETECIENTOS ”
End If
Case 4
TextoAux = TextoAux + “SIETE MIL ”
End Select
‘ 8
Case “8”
Select Case Posicion
Case 1, 7
If Posicion = 7 Then
TextoAux = TextoAux + “OCHO MILLONES ”
Else
TextoAux = TextoAux + “OCHO ”
End If
Case 2, 5, 8
If Siguiente = “0” Then
TextoAux = TextoAux + “OCHENTA ”
If Posicion = 5 Then TextoAux = TextoAux + “MIL ”
If Posicion = 8 Then TextoAux = TextoAux + “MILLONES ”
Else
TextoAux = TextoAux + “OCHENTA Y ”
End If
Case 3, 6, 9
If Siguiente = “0” And PostSiguiente = “0” Then
TextoAux = TextoAux + “OCHOCIENTOS ”
If Posicion = 6 Then TextoAux = TextoAux + “MIL ”
If Posicion = 9 Then TextoAux = TextoAux + “MILLONES ”
Else
TextoAux = TextoAux + “OCHOCIENTOS ”
End If
Case 4
TextoAux = TextoAux + “OCHO MIL ”
End Select
‘ 9
Case “9”
Select Case Posicion
Case 1, 7
If Posicion = 7 Then
TextoAux = TextoAux + “NUEVE MILLONES ”
Else
TextoAux = TextoAux + “NUEVE ”
End If
Case 2, 5, 8
If Siguiente = “0” Then
TextoAux = TextoAux + “NOVENTA ”
If Posicion = 5 Then TextoAux = TextoAux + “MIL ”
If Posicion = 8 Then TextoAux = TextoAux + “MILLONES ”
Else
TextoAux = TextoAux + “NOVENTA Y ”
End If
Case 3, 6, 9
If Siguiente = “0” And PostSiguiente = “0” Then
TextoAux = TextoAux + “NOVECIENTOS ”
If Posicion = 6 Then TextoAux = TextoAux + “MIL ”
If Posicion = 9 Then TextoAux = TextoAux + “MILLONES ”
Else
TextoAux = TextoAux + “NOVECIENTOS ”
End If
Case 4
TextoAux = TextoAux + “NUEVE MIL ”
End Select
End Select
Next I
‘Evalua si la conversion sera “PESOS” O “DE PESOS” Ej: TRES “PESOS” O UN MILLON “DE PESOS”
Redondo = False
If LongValor > 6 Then
For J = LongValor To 1 Step -1
Scan = Mid(ValATexto, J, 1)
If Scan = “0” Then K = K + 1
If K = 6 Then
Redondo = True
Exit For
End If
Next J
Else
Redondo = False
End If
‘Muestra el resultado
If LongValor = 1 And Mid(ValATexto, 1, 1) = “1” Then ‘Por si el usuario digita $1 “UN PESO”
LaSumaDe = TextoAux + “PESO M/CTE. * * * *”
ElseIf Redondo = True Then
LaSumaDe = TextoAux + “DE PESOS M/CTE.* * * *”
Else
LaSumaDe = TextoAux + “PESOS M/CTE. * * * *”
End If
‘Comprendo que hay maneras más sofisticadas de realizar este procedimiento, _
pero la idea era escribirlo basandome en mi propio analisis como ser humano para leer cierta cantidad. _
Parto de observar el primer numero y el siguiente asi como la ubicación de estos dentro del valor a convertir; _
es decir sin calculo de unidades, decenas etc, sino en una forma más instintiva.
‘Este programita funciona perfecto, aunque por respeto a los puristas debo decir que se puede mejorar bastante el código. _
‘Aun no detecto errores pero…
‘
‘Cordialmente,
‘ _
LEONARDO _
buzondelo@yahoo.com pa’ los insultos.
End Sub
Ayúda sólo quiero leer calificaciones ejem. 9.9 me dé nueve punto nueve
mi e-mail
sally_default@hotmail.com
Igual se agradece por compartir el código en C# y para Excel.
Hey esta super la funcion, no saben como me mate pensando como hacer eso, si me suponia que algo si tenia q hacer (la gran sabana de codigo XD) pero me sirvio mucho!! gran aporte chavo!!!
Bueno amigos este es mi aporte a este tremendo algoritmo. Implemento una función aparte llamada ConvierteCifra, extraigo el entero, el decimal y uno ambas conversiones, espero sea de utilidad.
‘FUNCION CONVIERTECIFRA MEJORADO
Public Function ConvierteCifra(ByVal Valor As Double) As String
‘Declara variables
Dim Largo As Integer, Decimales As Double, strEntero As String, strDecimal As String
‘Obtiene longitud del valor
Largo = Len(CStr(Format(CDbl(Valor), “#,###.00”)))
‘Obtiene enteros
strEntero = Mid(CStr(Format(CDbl(Valor), “#,###.00”)), 1, Largo – 3)
‘Obtiene decimales
strDecimal = Mid(CStr(Format(CDbl(Valor), “#,###.00″)), Largo – 1)
‘Convierte el entero
ConvierteCifra = Num2TEXT(strEntero) & ” BOLIVARES FUERTES”
‘Si el Decimal es mayor a cero, se indican en letras también
If CInt(strDecimal) = 0 Then
ConvierteCifra = ConvierteCifra & ” EXACTOS”
Else
ConvierteCifra = ConvierteCifra & ” CON ” & Num2TEXT(strDecimal) & ” CÉNTIMOS”
End If
End Function
Este codigo es infalible con este no hay pele con numeros enteros, decimales, formatos etc, etc, etc.
Option Explicit
Option Compare Text
‘Declaradas a nivel de módulo
Dim unidad(0 To 9) As String
Dim decena(0 To 9) As String
Dim centena(0 To 10) As String
Dim deci(0 To 9) As String
Dim otros(0 To 15) As String
Private Sub InicializarArrays()
‘Asignar los valores
unidad(1) = “UN”
unidad(2) = “DOS”
unidad(3) = “TRES”
unidad(4) = “CUATRO”
unidad(5) = “CINCO”
unidad(6) = “SEIS”
unidad(7) = “SIETE”
unidad(8) = “OCHO”
unidad(9) = “NUEVE”
‘
decena(1) = “DIEZ”
decena(2) = “VEINTE”
decena(3) = “TREINTA”
decena(4) = “CUARENTA”
decena(5) = “CINCUENTA”
decena(6) = “SESENTA”
decena(7) = “SETENTA”
decena(8) = “OCENTA”
decena(9) = “NOVENTA”
‘
centena(1) = “CIENTO”
centena(2) = “DOSCIENTOS”
centena(3) = “TRESCIENTOS”
centena(4) = “CUATROCIENTOS”
centena(5) = “QUINIENTOS”
centena(6) = “SEISCIENTOS”
centena(7) = “SETECIENTOS”
centena(8) = “OCHOCIENTOS”
centena(9) = “NOVECIENTOS”
centena(10) = “CIEN” ‘Parche
‘
deci(1) = “DIECI”
deci(2) = “VEINTI”
deci(3) = “TREINTA Y ”
deci(4) = “CUARENTA Y ”
deci(5) = “CINCUENTA Y ”
deci(6) = “SESENTA Y ”
deci(7) = “SETENTA Y ”
deci(8) = “OCHENTA Y ”
deci(9) = “NOVENTA Y ”
‘
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”
otros(12) = “DOCE”
otros(13) = “TRECE”
otros(14) = “CATORCE”
otros(15) = “QUINCE”
End Sub (20/May/97)
Public Function Numero2Letra(ByVal strNum As String, Optional ByVal vLo, Optional ByVal vMoneda, Optional ByVal vCentimos) As String
‘———————————————————-
‘ Convierte el número strNum en letras (28/Feb/91)
‘ Versión para Windows (25/Oct/96)
‘ Variables estáticas (15/May/97)
‘ Parche de “Esteve”
‘ Revisión para decimales (10/Jul/97)
‘———————————————————-
Dim i As Integer
Dim Lo As Integer
Dim iHayDecimal As Integer ‘Posición del signo decimal
Dim sDecimal As String ‘Signo decimal a usar
Dim sEntero As String
Dim sFraccion As String
Dim fFraccion As Single
Dim sNumero As String
‘
Dim sMoneda As String
Dim sCentimos As String
‘Si se especifica, se usarán
If Not IsMissing(vMoneda) Then
sMoneda = ” ” & Trim$(vMoneda) & ” ”
Else
sMoneda = ” ”
End If
If Not IsMissing(vCentimos) Then
sCentimos = ” ” & Trim$(vCentimos)
End If
‘Averiguar el signo decimal
sNumero = Format$(25.5, “#.#”)
If InStr(sNumero, “.”) Then
sDecimal = “.”
Else
sDecimal = “,”
End If
‘Si no se especifica el ancho…
If IsMissing(vLo) Then
Lo = 0
Else
Lo = vLo
End If
‘
If Lo Then
sNumero = Space$(Lo)
Else
sNumero = “”
End If
‘Quitar los espacios que haya por medio
Do
i = InStr(strNum, ” “)
If i = 0 Then Exit Do
strNum = Left$(strNum, i – 1) & Mid$(strNum, i + 1)
Loop
‘Comprobar si tiene decimales
iHayDecimal = InStr(strNum, sDecimal)
If iHayDecimal Then
sEntero = Left$(strNum, iHayDecimal – 1)
sFraccion = Mid$(strNum, iHayDecimal + 1) & “00”
‘obligar a que tenga dos cifras
sFraccion = Left$(sFraccion, 2)
fFraccion = Val(sFraccion)
‘Si no hay decimales… no agregar nada…
If fFraccion < 1 Then strNum = RTrim$(UnNumero(sEntero) & sMoneda & " EXACTOS") If Lo Then LSet sNumero = strNum Else sNumero = strNum End If Numero2Letra = sNumero Exit Function End If sEntero = UnNumero(sEntero) sFraccion = UnNumero(sFraccion) ' strNum = sEntero & sMoneda & "BOLIVARES CON " & sFraccion & sCentimos & " CENTIMOS" If Lo Then LSet sNumero = RTrim$(strNum) Else sNumero = RTrim$(strNum) End If Numero2Letra = sNumero Else strNum = RTrim$(UnNumero(strNum) & sMoneda & " EXACTOS") If Lo Then LSet sNumero = strNum Else sNumero = strNum End If Numero2Letra = sNumero End If End Function Private Function UnNumero(ByVal strNum As String) As String '---------------------------------------------------------- 'Esta es la rutina principal (10/Jul/97) 'Está separada para poder actuar con decimales '---------------------------------------------------------- Dim lngA As Double Dim Negativo As Boolean Dim L As Integer Dim Una As Boolean Dim Millon As Boolean Dim Millones As Boolean Dim vez As Integer Dim MaxVez As Integer Dim k As Integer Dim strQ As String Dim strB As String Dim strU As String Dim strD As String Dim strC As String Dim iA As Integer ' Dim strN() As String 'Si se amplia este valor... no se manipularán bien los números Const cAncho = 12 Const cGrupos = cAncho \ 3 ' If unidad(1) <> “UNA” Then
InicializarArrays
End If
‘Si se produce un error que se pare el mundo!!!
On Local Error GoTo 0
lngA = Abs(CDbl(strNum))
Negativo = (lngA <> CDbl(strNum))
strNum = LTrim$(RTrim$(Str$(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(1 To 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 = Val(Right$(strNum, 2))
If Right$(strNum, 1) = “0” Then
k = k \ 10
strD = decena(k)
ElseIf k > 10 And k < 16 Then k = Val(Mid$(strNum, L - 1, 2)) strD = otros(k) Else strU = unidad(Val(Right$(strNum, 1))) If L - 1 > 0 Then
k = Val(Mid$(strNum, L – 1, 1))
strD = deci(k)
End If
End If
‘—Parche de Esteve
If L – 2 > 0 Then
k = Val(Mid$(strNum, L – 2, 1))
‘Con esto funcionará bien el 100100, por ejemplo…
If k = 1 Then ‘Parche
If Val(strNum) = 100 Then ‘Parche
k = 10 ‘Parche
End If ‘Parche
End If
strC = centena(k) & ” ”
End If
‘——
If strU = “UNO” And Left$(strB, 4) = ” MIL” Then strU = “”
strB = strC & strD & strU & ” ” & strB
If (vez = 1 Or vez = 3) Then
If strN(vez + 1) <> “000” Then strB = ” MIL ” & strB
End If
If vez = 2 And Millon Then
If Millones Then
strB = ” MILLONES ” & strB
Else
strB = “UN MILLON ” & strB
End If
End If
Next
strB = Trim$(strB)
If Right$(strB, 3) = “UNO” Then strB = Left$(strB, Len(strB) – 1) & “A”
Do ‘Quitar los espacios que haya por medio
iA = InStr(strB, ” “)
If iA = 0 Then Exit Do
strB = Left$(strB, iA – 1) & Mid$(strB, iA + 1)
Loop
If Left$(strB, 6) = “UNO UN” Then strB = Mid$(strB, 5)
If Left$(strB, 7) = “UNO MIL” Then strB = Mid$(strB, 5)
If Right$(strB, 16) <> “MILLONES MIL UNO” Then
iA = InStr(strB, “MILLONES MIL UN”)
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
AYUDA… TODAS LAS FUNCIONES ME SIRVEN EN EXCEL… MUCHAS GRACIAS… PERO DESPUÉS DE CERRAR EL ARCHIVO Y VOLVERLO A ABRIR… NADA NO RECONOCE LA FUNCIÓN… PO FAVO AYUDA… MI E-MAIL ES: sally_default@hotmail.com
Hola que tal, disculpa que pregunte mi hermano, pero fijate que ya mi cabeza va estallar y no puedo encontrar nada mas y recurro a ti.
Mira.
En un formulario que me sirve de catalogo de productos inserte lo siguiente;
El catalogo (formulario) tiene una cuadro de control que me sirve de buscardor, si yo inserto un codigo de un producto, este me da la informacion del producto, tales como; descripcion, proveedor, precio, ubicacion. Y aparte inserté dos subformularios. Uno es de las entradas de los productos y el otro de las salidas. Están a modo de resumen, despues de esto inserté un cuadro de texto en donde resto las salidas de las entradas, algo asi:
=nz([Subformulario ENTRADA PRODUCTOS PROVEEDOR Consulta6].Formulario![Suma De CANTIDAD],0)-nz([Subformulario PUNTO VENTA Consulta6].Formulario![Suma De CANTIDAD],0)
Cuando hay datos me da correctamente la cantidad que hay en stock, pero si en alguno de los subformularios no hay datos(o valor nulo) este mme da ERROR.
Como podría hacerle? Me podrías ayudar?
Gracias
martin_aguilar_mariscal@hotmail.com
Tengo esta pero me hace falta incluir cuando es por ejemplo 1200.00 que diga “mil doscientos con 00/100”, osea no se en que parte poner ra que cuando no tenga decimales salga “00/100”
Me puedn ayudar por favor a ver donde debo incluir esto!!??
Function letra(Numero)
Dim Texto
Dim Millones
Dim Miles
Dim Cientos
Dim Decimales
Dim Cadena
Dim CadMillones
Dim CadMiles
Dim CadCientos
Dim caddecimales
Texto = Round(Numero, 2)
Texto = FormatNumber(Texto, 2)
Texto = Right(Space(14) & Texto, 14)
Millones = Mid(Texto, 1, 3)
Miles = Mid(Texto, 5, 3)
Cientos = Mid(Texto, 9, 3)
Decimales = Mid(Texto, 13, 2)
CadMillones = ConvierteCifra(Millones, False)
CadMiles = ConvierteCifra(Miles, False)
CadCientos = ConvierteCifra(Cientos, True)
caddecimales = ConvierteDecimal(Decimales)
If Trim(CadMillones) > “” Then
If Trim(CadMillones) = “UN” Then
Cadena = CadMillones & ” MILLON”
Else
Cadena = CadMillones & ” MILLONES”
End If
End If
If Trim(CadMiles) > “” Then
If Trim(CadMiles) = “UN” Then
CadMiles = “”
Cadena = Cadena & “” & CadMiles & “MIL”
CadMiles = “UN”
Else
Cadena = Cadena & ” ” & CadMiles & ” MIL”
End If
End If
If Trim(CadMiles) > “001” Then
CadMiles = “MIL”
End If
If Decimales = “00” Then
If Trim(CadMillones & CadMiles & CadCientos & caddecimales) = “UN” Then
Cadena = Cadena & “UNO ”
Else
If Miles & Cientos = “000000” Then
Cadena = Cadena & ” ” & Trim(CadCientos)
Else
Cadena = Cadena & ” ” & Trim(CadCientos)
End If
letra = Trim(Cadena)
End If
Else
If Trim(CadMillones & CadMiles & CadCientos & caddecimales) = “UN” Then
Cadena = Cadena & “UNO ” & “CON ” & Trim(caddecimales)
Else
If Millones & Miles & Cientos & Decimales = “000000” Then
Cadena = Cadena & ” ” & Trim(CadCientos) & ” CON ” & Trim(Decimales) & “/100″
Else
Cadena = Cadena & ” ” & Trim(CadCientos) & ” CON ” & Trim(Decimales) & “/100”
End If
letra = Trim(Cadena)
End If
End If
End Function
Function ConvierteCifra(Texto, IsCientos As Boolean)
Dim Centena
Dim Decena
Dim Unidad
Dim txtCentena
Dim txtDecena
Dim txtUnidad
Centena = Mid(Texto, 1, 1)
Decena = Mid(Texto, 2, 1)
Unidad = Mid(Texto, 3, 1)
Select Case Centena
Case “1”
txtCentena = “CIEN”
If Decena & Unidad <> “00” Then
txtCentena = “CIENTO”
End If
Case “2”
txtCentena = “DOSCIENTOS”
Case “3”
txtCentena = “TRESCIENTOS”
Case “4”
txtCentena = “CUATROCIENTOS”
Case “5”
txtCentena = “QUINIENTOS”
Case “6”
txtCentena = “SEISCIENTOS”
Case “7”
txtCentena = “SETECIENTOS”
Case “8”
txtCentena = “OCHOCIENTOS”
Case “9”
txtCentena = “NOVECIENTOS”
End Select
Select Case Decena
Case “1”
txtDecena = “DIEZ”
Select Case Unidad
Case “1”
txtDecena = “ONCE”
Case “2”
txtDecena = “DOCE”
Case “3”
txtDecena = “TRECE”
Case “4”
txtDecena = “CATORCE”
Case “5”
txtDecena = “QUINCE”
Case “6”
txtDecena = “DIECISEIS”
Case “7”
txtDecena = “DIECISIETE”
Case “8”
txtDecena = “DIECIOCHO”
Case “9”
txtDecena = “DIECINUEVE”
End Select
Case “2”
txtDecena = “VEINTE”
If Unidad <> “0” Then
txtDecena = “VEINTI”
End If
Case “3”
txtDecena = “TREINTA”
If Unidad <> “0” Then
txtDecena = “TREINTA Y ”
End If
Case “4”
txtDecena = “CUARENTA”
If Unidad <> “0” Then
txtDecena = “CUARENTA Y ”
End If
Case “5”
txtDecena = “CINCUENTA”
If Unidad <> “0” Then
txtDecena = “CINCUENTA Y ”
End If
Case “6”
txtDecena = “SESENTA”
If Unidad <> “0” Then
txtDecena = “SESENTA Y ”
End If
Case “7”
txtDecena = “SETENTA”
If Unidad <> “0” Then
txtDecena = “SETENTA Y ”
End If
Case “8”
txtDecena = “OCHENTA”
If Unidad <> “0” Then
txtDecena = “OCHENTA Y ”
End If
Case “9”
txtDecena = “NOVENTA”
If Unidad <> “0” Then
txtDecena = “NOVENTA Y ”
End If
End Select
If Decena <> “1” Then
Select Case Unidad
Case “1”
If IsCientos = False Then
txtUnidad = “UN”
Else
txtUnidad = “UNO”
End If
Case “2”
txtUnidad = “DOS”
Case “3”
txtUnidad = “TRES”
Case “4”
txtUnidad = “CUATRO”
Case “5”
txtUnidad = “CINCO”
Case “6”
txtUnidad = “SEIS”
Case “7”
txtUnidad = “SIETE”
Case “8”
txtUnidad = “OCHO”
Case “9”
txtUnidad = “NUEVE”
End Select
End If
ConvierteCifra = txtCentena & ” ” & txtDecena & txtUnidad
End Function
Function ConvierteDecimal(Texto)
Dim Decenadecimal
Dim Unidaddecimal
Dim txtDecenadecimal
Dim txtUnidaddecimal
Decenadecimal = Mid(Texto, 1, 1)
Unidaddecimal = Mid(Texto, 2, 1)
Select Case Decenadecimal
Case “0”
Case “1”
txtDecenadecimal = “DIEZ”
Select Case Unidaddecimal
Case “0”
Case “1”
txtDecenadecimal = “ONCE”
Case “2”
txtDecenadecimal = “DOCE”
Case “3”
txtDecenadecimal = “TRECE”
Case “4”
txtDecenadecimal = “CATORCE”
Case “5”
txtDecenadecimal = “QUINCE”
Case “6”
txtDecenadecimal = “DIECISEIS”
Case “7”
txtDecenadecimal = “DIECISIETE”
Case “8”
txtDecenadecimal = “DIECIOCHO”
Case “9”
txtDecenadecimal = “DIECINUEVE”
End Select
Case “2”
txtDecenadecimal = “VEINTE”
If Unidaddecimal <> “0” Then
txtDecenadecimal = “VEINTI”
End If
Case “3”
txtDecenadecimal = “TREINTA”
If Unidaddecimal <> “0” Then
txtDecenadecimal = “TREINTA Y ”
End If
Case “4”
txtDecenadecimal = “CUARENTA”
If Unidaddecimal <> “0” Then
txtDecenadecimal = “CUARENTA Y ”
End If
Case “5”
txtDecenadecimal = “CINCUENTA”
If Unidaddecimal <> “0” Then
txtDecenadecimal = “CINCUENTA Y ”
End If
Case “6”
txtDecenadecimal = “SESENTA”
If Unidaddecimal <> “0” Then
txtDecenadecimal = “SESENTA Y ”
End If
Case “7”
txtDecenadecimal = “SETENTA”
If Unidaddecimal <> “0” Then
txtDecenadecimal = “SETENTA Y ”
End If
Case “8”
txtDecenadecimal = “OCHENTA”
If Unidaddecimal <> “0” Then
txtDecenadecimal = “OCHENTA Y ”
End If
Case “9”
txtDecenadecimal = “NOVENTA”
If Unidaddecimal <> “0” Then
txtDecenadecimal = “NOVENTA Y ”
End If
End Select
If Decenadecimal <> “1” Then
Select Case Unidaddecimal
Case “1”
txtUnidaddecimal = “UNO”
Case “2”
txtUnidaddecimal = “DOS”
Case “3”
txtUnidaddecimal = “TRES”
Case “4”
txtUnidaddecimal = “CUATRO”
Case “5”
txtUnidaddecimal = “CINCO”
Case “6”
txtUnidaddecimal = “SEIS”
Case “7”
txtUnidaddecimal = “SIETE”
Case “8”
txtUnidaddecimal = “OCHO”
Case “9”
txtUnidaddecimal = “NUEVE”
End Select
End If
If Decenadecimal = 0 And Unidaddecimal = 0 Then
ConvierteDecimal = ” ”
Else
ConvierteDecimal = txtDecenadecimal & txtUnidaddecimal
End If
End Function
como utlizo la funcion de convertir letras a nuero en asp
Creo que debería funcionar en asp cambiando solo el encabezado de la función:
Cambia esto:
Public Function Num2Text(ByVal value As Double) As String
Por esto otro:
Function Num2Text(ByVal value)
Prueba y nos cuentas 🙂
Estoy empezando en ASP NET y quisiera saber como utilizo la funcion de letras a numeros. ya que an llamar la funcion, como indico abajo, siempre me escribe CERO en la caja de texto.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim value As Integer ‘or String or Double
TextBox1.Text = Num2Text(value)
End Sub
Public Function Num2Text(ByVal value As Double) As String
Select Case value
Case 0 : Num2Text = “CERO”
Case 1 : Num2Text = “UN”
……………. End Function
Hola Nohemi,
El problema lo tienes aca:
Dim value As Integer ‘or String or Double
TextBox1.Text = Num2Text(value)
Si te das cuenta no estás pasando ningun valor a la función, prueba con lo siguiente:
Dim value As Integer
value=123
TextBox1.Text = Num2Text(value)
Saludos,
Jhonny Vargas P.
Hola Que tal estoy haciendo una base de datos la cual debo registras datos como:
Folio:
Nombre de Solicitante:
Importe:
Fecha:
Banco:
Cuenta:
Observaciones:
Todo esta bien la tabla y el Formulario en donde tengo problemas es en el informe ya que no se como colocar el codigo para que el importe sea convertido en letras.
Les agradeceria mucho su ayuda ya que llevo muy poquito en access.
Ejemplo de Convercion (Dos Mil Quinientos treinta y tres pesos 83/100 M.N.)
De Antemano Gracias
Implemente satisfactoriamente el algoritmo en un sistema… mejores resultados imposible obtener, lo recomiendo ampliamente
arael82@gmail.com
como le agrego la palabra pesos al final ???
Funciona a la perfeccion, pero tengo una duda. Para usarlo en un PDF necesito javascript cual tendria q ser el codigo?
Gracias espero q alguien responda pronto =)
…ok soy algo novato,yo en mi caso lo que quiero es algo mas simple (pienso yo) ya que no requiere ninguna implementacion externa, es esto mismo convertir numeros a letras en VB.net pero sea una aplicacion en consola…yo ya estoy es totalmente mareado de visitar web tras web hasta en ingles y nada…
sludos espero puedan ayudarme, el codigo debe de ser de lo mas basico.
perdon por las molestias.
geller90@hotmail.com
MR.VARGAS.
Ayudeme por favor necesito convertir 9.8 en NUEVE PUNTO OCHO en excel 2003 soy ignorante en le materia manejo lo elemental de excel. gracias
hola un no se como aplicar el codigo sin que redondehe la cantidad y usarlo con la leyenda de “Pesos 00/100 M.N.”
tengo el texto31 en donde me aparece la cantidad en numero y el texto35 donde quiere poner la cantidad en Letra.
ojala que alguien me pueda ayudar.. este es mi correo gonzalo403@hotmail.com
gracias!
Necesito saber como se llama cada cuadro de texto para elaborar el form1 y cuantos label voy a usar y cuantos textbox.
les dejo mi correo por si tienen la amabilidad de poder ayudarme .
Gracias .
C.guillen@hotmail.es
Option Explicit
Option Compare Text
‘Declaradas a nivel de módulo
Dim unidad(0 To 9) As String
Dim decena(0 To 9) As String
Dim centena(0 To 10) As String
Dim deci(0 To 9) As String
Dim otros(0 To 15) As String
Private Sub InicializarArrays()
‘Asignar los valores
unidad(1) = “UN”
unidad(2) = “DOS”
unidad(3) = “TRES”
unidad(4) = “CUATRO”
unidad(5) = “CINCO”
unidad(6) = “SEIS”
unidad(7) = “SIETE”
unidad(8) = “OCHO”
unidad(9) = “NUEVE”
‘
decena(1) = “DIEZ”
decena(2) = “VEINTE”
decena(3) = “TREINTA”
decena(4) = “CUARENTA”
decena(5) = “CINCUENTA”
decena(6) = “SESENTA”
decena(7) = “SETENTA”
decena(8) = “OCENTA”
decena(9) = “NOVENTA”
‘
centena(1) = “CIENTO”
centena(2) = “DOSCIENTOS”
centena(3) = “TRESCIENTOS”
centena(4) = “CUATROCIENTOS”
centena(5) = “QUINIENTOS”
centena(6) = “SEISCIENTOS”
centena(7) = “SETECIENTOS”
centena(8) = “OCHOCIENTOS”
centena(9) = “NOVECIENTOS”
centena(10) = “CIEN” ‘Parche
‘
deci(1) = “DIECI”
deci(2) = “VEINTI”
deci(3) = “TREINTA Y ”
deci(4) = “CUARENTA Y ”
deci(5) = “CINCUENTA Y ”
deci(6) = “SESENTA Y ”
deci(7) = “SETENTA Y ”
deci(8) = “OCHENTA Y ”
deci(9) = “NOVENTA Y ”
‘
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”
otros(12) = “DOCE”
otros(13) = “TRECE”
otros(14) = “CATORCE”
otros(15) = “QUINCE”
End Sub
Public Function Numero2Letra(ByVal strNum As String, Optional ByVal vLo, Optional ByVal vMoneda, Optional ByVal vCentimos) As String
‘———————————————————-
‘ Convierte el número strNum en letras (28/Feb/91)
‘ Versión para Windows (25/Oct/96)
‘ Variables estáticas (15/May/97)
‘ Parche de “Esteve” (20/May/97)
‘ Revisión para decimales (10/Jul/97)
‘———————————————————-
Dim i As Integer
Dim Lo As Integer
Dim iHayDecimal As Integer ‘Posición del signo decimal
Dim sDecimal As String ‘Signo decimal a usar
Dim sEntero As String
Dim sFraccion As String
Dim fFraccion As Single
Dim sNumero As String
‘
Dim sMoneda As String
Dim sCentimos As String
‘Si se especifica, se usarán
If Not IsMissing(vMoneda) Then
sMoneda = ” ” & Trim$(vMoneda) & ” ”
Else
sMoneda = ” ”
End If
If Not IsMissing(vCentimos) Then
sCentimos = ” ” & Trim$(vCentimos)
End If
‘Averiguar el signo decimal
sNumero = Format$(25.5, “#.#”)
If InStr(sNumero, “.”) Then
sDecimal = “.”
Else
sDecimal = “,”
End If
‘Si no se especifica el ancho…
If IsMissing(vLo) Then
Lo = 0
Else
Lo = vLo
End If
‘
If Lo Then
sNumero = Space$(Lo)
Else
sNumero = “”
End If
‘Quitar los espacios que haya por medio
Do
i = InStr(strNum, ” “)
If i = 0 Then Exit Do
strNum = Left$(strNum, i – 1) & Mid$(strNum, i + 1)
Loop
‘Comprobar si tiene decimales
iHayDecimal = InStr(strNum, sDecimal)
If iHayDecimal Then
sEntero = Left$(strNum, iHayDecimal – 1)
sFraccion = Mid$(strNum, iHayDecimal + 1) & “00”
‘obligar a que tenga dos cifras
sFraccion = Left$(sFraccion, 2)
fFraccion = Val(sFraccion)
‘Si no hay decimales… no agregar nada…
If fFraccion < 1 Then strNum = RTrim$(UnNumero(sEntero) & sMoneda & " EXACTOS") If Lo Then LSet sNumero = strNum Else sNumero = strNum End If Numero2Letra = sNumero Exit Function End If sEntero = UnNumero(sEntero) sFraccion = UnNumero(sFraccion) ' strNum = sEntero & sMoneda & "BOLIVARES CON " & sFraccion & sCentimos & " CENTIMOS" If Lo Then LSet sNumero = RTrim$(strNum) Else sNumero = RTrim$(strNum) End If Numero2Letra = sNumero Else strNum = RTrim$(UnNumero(strNum) & sMoneda & " EXACTOS") If Lo Then LSet sNumero = strNum Else sNumero = strNum End If Numero2Letra = sNumero End If End Function Private Function UnNumero(ByVal strNum As String) As String '---------------------------------------------------------- 'Esta es la rutina principal (10/Jul/97) 'Está separada para poder actuar con decimales '---------------------------------------------------------- Dim lngA As Double Dim Negativo As Boolean Dim L As Integer Dim Una As Boolean Dim Millon As Boolean Dim Millones As Boolean Dim vez As Integer Dim MaxVez As Integer Dim k As Integer Dim strQ As String Dim strB As String Dim strU As String Dim strD As String Dim strC As String Dim iA As Integer ' Dim strN() As String 'Si se amplia este valor... no se manipularán bien los números Const cAncho = 12 Const cGrupos = cAncho \ 3 ' If unidad(1) <> “UNA” Then
InicializarArrays
End If
‘Si se produce un error que se pare el mundo!!!
On Local Error GoTo 0
lngA = Abs(CDbl(strNum))
Negativo = (lngA <> CDbl(strNum))
strNum = LTrim$(RTrim$(Str$(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(1 To 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 = Val(Right$(strNum, 2))
If Right$(strNum, 1) = “0” Then
k = k \ 10
strD = decena(k)
ElseIf k > 10 And k < 16 Then k = Val(Mid$(strNum, L - 1, 2)) strD = otros(k) Else strU = unidad(Val(Right$(strNum, 1))) If L - 1 > 0 Then
k = Val(Mid$(strNum, L – 1, 1))
strD = deci(k)
End If
End If
‘—Parche de Esteve
If L – 2 > 0 Then
k = Val(Mid$(strNum, L – 2, 1))
‘Con esto funcionará bien el 100100, por ejemplo…
If k = 1 Then ‘Parche
If Val(strNum) = 100 Then ‘Parche
k = 10 ‘Parche
End If ‘Parche
End If
strC = centena(k) & ” ”
End If
‘——
If strU = “UNO” And Left$(strB, 4) = ” MIL” Then strU = “”
strB = strC & strD & strU & ” ” & strB
If (vez = 1 Or vez = 3) Then
If strN(vez + 1) <> “000” Then strB = ” MIL ” & strB
End If
If vez = 2 And Millon Then
If Millones Then
strB = ” MILLONES ” & strB
Else
strB = “UN MILLON ” & strB
End If
End If
Next
strB = Trim$(strB)
If Right$(strB, 3) = “UNO” Then strB = Left$(strB, Len(strB) – 1) & “A”
Do ‘Quitar los espacios que haya por medio
iA = InStr(strB, ” “)
If iA = 0 Then Exit Do
strB = Left$(strB, iA – 1) & Mid$(strB, iA + 1)
Loop
If Left$(strB, 6) = “UNO UN” Then strB = Mid$(strB, 5)
If Left$(strB, 7) = “UNO MIL” Then strB = Mid$(strB, 5)
If Right$(strB, 16) <> “MILLONES MIL UNO” Then
iA = InStr(strB, “MILLONES MIL UN”)
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
Muy buen codigo, perfecto, muchas gracias.
Esta chido este algoritmo pero ya me dio un error (al menos a mi me aparece) traten de convertir este número:
123456789
A parte, el compilador me marca error ya que tengo Option Strict On el error esta en las instrucciones if, ya que se esta comparando un Integer con un Boolean, lo cual esto es incompatible con Option Strict On
Muchas gracias men, esta formula me resulto de maravilla, he usado varios codigos, pero no me resultaba a la perfeccion.
Nuevamente gracias por tu aporte.
Andres
Santiago de Chile
esta muy mal lo de convertir los numeros romanos en letras
Muchas gracias por compartir el código, funciona perfecto 😉
Hola a todos, que decir que estuve usando el codigo de conversion para access y cuando trato de usar este codigo como modulo los numero mayores de 5 al final ejemplo: 656 me pone “seiscientos cincuenta y seis” osea me pose un numero por encima y cuando trato de arreglarlo poniendo -1 al final esos numero si los corrige pero los menoes de 5 entonces le quita uno. No se si esto solo me pasa a mi y a otros trambien el caso es ke no se koco arreglarlo… alguien puede ayudar?
gracias de antemano.
Hola nuevamente acabo de darme cuenta que es el problema anteriormente decrito por mi y es asunto es que cuando uso decimales, la funcion me redondea la cifra por ejemplo si uso 342.70 ya redondea a 342.00 y en el resultado se muestra y eso no lo necesito pq me cambia el resultado. alguien sabe como solucionar esto?
Muy bueno el código, tenía tiempo buscándolo.
Si, no se mucho de programacion, pero es que estoy haciendo unas facturas en exel, y no se como se hace para poner el codigo en exel para que en una casilla me salga en letras el TOTAL de la factura, GRACIAS POR LA AYUDA QUE ME PUEDAN BRINDAR
Hola bueno estuve dandome de topoes al no poder usar sus codigos puesto que unos ponen un codigo y luego otro pone el mismo pero con diferentes variables y dicen que le agregaron no se que y ni si quiera ponen en donde ni como le hicieron miren yo hice esto, pruebenlo y si les sirve lo adecuan, para los centavos solo puse en lugar de un TextBox para los centavos, un MaskTextBox y lo adecue solo para que puedan introducir 2 numeros pueden usarlo con la misma funcion de los pesos obvio el masktextbox solo permite lo numeros que tu quieras asi me evite problemas:
Public Class Form1
Public Function Num2Text(ByVal value As Double) As String
Select Case value
Case 0 : Num2Text = “CERO”
Case 1 : Num2Text = “UN”
Case 2 : Num2Text = “DOS”
Case 3 : Num2Text = “TRES”
Case 4 : Num2Text = “CUATRO”
Case 5 : Num2Text = “CINCO”
Case 6 : Num2Text = “SEIS”
Case 7 : Num2Text = “SIETE”
Case 8 : Num2Text = “OCHO”
Case 9 : Num2Text = “NUEVE”
Case 10 : Num2Text = “DIEZ”
Case 11 : Num2Text = “ONCE”
Case 12 : Num2Text = “DOCE”
Case 13 : Num2Text = “TRECE”
Case 14 : Num2Text = “CATORCE”
Case 15 : Num2Text = “QUINCE”
Case Is < 20 : Num2Text = "DIECI" & Num2Text(value - 10) Case 20 : Num2Text = "VEINTE" Case Is < 30 : Num2Text = "VEINTI" & Num2Text(value - 20) Case 30 : Num2Text = "TREINTA" Case 40 : Num2Text = "CUARENTA" Case 50 : Num2Text = "CINCUENTA" Case 60 : Num2Text = "SESENTA" Case 70 : Num2Text = "SETENTA" Case 80 : Num2Text = "OCHENTA" Case 90 : Num2Text = "NOVENTA" Case Is < 100 : Num2Text = Num2Text(Int(value \ 10) * 10) & " Y " & Num2Text(value Mod 10) Case 100 : Num2Text = "CIEN" Case Is < 200 : Num2Text = "CIENTO " & Num2Text(value - 100) Case 200, 300, 400, 600, 800 : Num2Text = Num2Text(Int(value \ 100)) & "CIENTOS" Case 500 : Num2Text = "QUINIENTOS" Case 700 : Num2Text = "SETECIENTOS" Case 900 : Num2Text = "NOVECIENTOS" Case Is < 1000 : Num2Text = Num2Text(Int(value \ 100) * 100) & " " & Num2Text(value Mod 100) Case 1000 : Num2Text = "MIL" Case Is < 2000 : Num2Text = "MIL " & Num2Text(value Mod 1000) Case Is < 1000000 : Num2Text = Num2Text(Int(value \ 1000)) & " MIL" If value Mod 1000 Then Num2Text = Num2Text & " " & Num2Text(value Mod 1000) Case 1000000 : Num2Text = "UN MILLON" Case Is < 2000000 : Num2Text = "UN MILLON " & Num2Text(value Mod 1000000) Case Is < 1000000000000.0# : Num2Text = Num2Text(Int(value / 1000000)) & " MILLONES " If (value - Int(value / 1000000) * 1000000) Then Num2Text = Num2Text & " " & Num2Text(value - Int(value / 1000000) * 1000000) Case 1000000000000.0# : Num2Text = "UN BILLON" Case Is < 2000000000000.0# : Num2Text = "UN BILLON " & Num2Text(value - Int(value / 1000000000000.0#) * 1000000000000.0#) Case Else : Num2Text = Num2Text(Int(value / 1000000000000.0#)) & " BILLONES" If (value - Int(value / 1000000000000.0#) * 1000000000000.0#) Then Num2Text = Num2Text & " " & Num2Text(value - Int(value / 1000000000000.0#) * 1000000000000.0#) End Select End Function Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim numero As Integer Dim numero2 As Integer If TextBox1.Text = "" Or TextBox2.Text = "" Then MsgBox("Debe poner todos los datos, pesos y centavos", MsgBoxStyle.OkOnly, "Error") Else numero = TextBox1.Text numero2 = TextBox2.Text 'Aqui la linea comentada pueden poner que los centavos aparezcan en numero & numero2 & , o que aparezcan en text solo cambien la linea = solo que en lugar de poner $ numero2 & "/100 M.N. " ponen Num2Texto(numero2) y listo, espero les sirva de algo =) pesos.Text = Num2Text(numero) & " PESOS " & numero2 & "/100 M.N." Me.Hide() My.Forms.ImpresionHSBC.Show() End If End Sub Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load TextBox1.Focus() End Sub End Class
hola la verdad no entiendo mucho de esto he estado intentando hacer la operacion en macros pero no tengo ni idea de como
no tengo muchos conocimientos de esto asi que ojala y me puedas ayuda a resolver paso a paso para instalar todo lo anterior gracias
Facil de usar, simplemente un exquisito codigo.
Gracias!!
Excelente codigo de vino de maravillas. Solo estoy teniendo problemas con la parte de decimales, si alguien me da una mano se agradece!.
GRacias!!
Me ahorro tiempo de programación, lo pase a MSSQL ya que lo necesitaba para la base de datos, el código sirve desde la versión 2000, les dejo el código convertido para una función
wr
Create Function dbo.Num2Text(@valor money)
returns varchar(500)
as
begin
declare @textoValor varchar(500)
Select @textoValor = Case when @valor = 0 then ‘CERO’
when @valor = 1 then ‘UN’
when @valor = 2 then ‘DOS’
when @valor = 3 then ‘TRES’
when @valor = 4 then ‘CUATRO’
when @valor = 5 then ‘CINCO’
when @valor = 6 then ‘SEIS’
when @valor = 7 then ‘SIETE’
when @valor = 8 then ‘OCHO’
when @valor = 9 then ‘NUEVE’
when @valor = 10 then ‘DIEZ’
when @valor = 11 then ‘ONCE’
when @valor = 12 then ‘DOCE’
when @valor = 13 then ‘TRECE’
when @valor = 14 then ‘CATORCE’
when @valor = 15 then ‘QUINCE’
when @valor < 20 then 'DIECI' + dbo.Num2Text(@valor - 10) when @valor = 20 then 'VEINTE' when @valor < 30 then 'VEINTI' + dbo.Num2Text(@valor - 20) when @valor = 30 then 'TREINTA' when @valor = 40 then 'CUARENTA' when @valor = 50 then 'CINCUENTA' when @valor = 60 then 'SESENTA' when @valor = 70 then 'SETENTA' when @valor = 80 then 'OCHENTA' when @valor = 90 then 'NOVENTA' when @valor < 100 then dbo.Num2Text(floor(@valor / 10) * 10) + ' Y ' + dbo.Num2Text(@valor % 10) when @valor = 100 then 'CIEN' when @valor < 200 then 'CIENTO ' + dbo.Num2Text(@valor - 100) when @valor in (200, 300, 400, 600, 800) then dbo.Num2Text(floor(@valor / 100)) + 'CIENTOS' when @valor = 500 then 'QUINIENTOS' when @valor = 700 then 'SETECIENTOS' when @valor = 900 then 'NOVECIENTOS' when @valor < 1000 then dbo.Num2Text(floor(@valor / 100) * 100) + ' ' + dbo.Num2Text(@valor % 100) when @valor = 1000 then 'MIL' when @valor < 2000 then 'MIL ' + dbo.Num2Text(@valor % 1000) when @valor < 1000000 then case when @valor % 1000 > 0
then dbo.Num2Text(floor(@valor / 1000)) + ‘ MIL’ + ‘ ‘ + dbo.Num2Text(@valor % 1000)
else dbo.Num2Text(floor(@valor / 1000)) + ‘ MIL’
end
when @valor = 1000000 then ‘UN MILLON’
when @valor < 2000000 then 'UN MILLON ' + dbo.Num2Text(@valor % 1000000) when @valor < 1000000000000.0 then case when (@valor - floor(@valor / 1000000) * 1000000) > 0
then dbo.Num2Text(floor(@valor / 1000000)) + ‘ MILLONES ‘ + dbo.Num2Text(@valor – floor(@valor / 1000000) * 1000000)
else dbo.Num2Text(floor(@valor / 1000000)) + ‘ MILLONES ‘
end
when @valor = 1000000000000.0 then ‘UN BILLON’
when @valor < 2000000000000.0 then 'UN BILLON ' + dbo.Num2Text(@valor - floor(@valor / 1000000000000.0) * 1000000000000.0) else case when (@valor - floor(@valor / 1000000000000.0) * 1000000000000.0) > 0
then dbo.Num2Text(floor(@valor / 1000000000000.0)) + ‘ BILLONES’
else dbo.Num2Text(floor(@valor / 1000000000000.0)) + ‘ BILLONES’ + ‘ ‘ + dbo.Num2Text(@valor – floor(@valor / 1000000000000.0) * 1000000000000.0)
end
end
return(@textoValor)
end
hola necesito q me ayuden quiero convertir una contraseña en asteriscos
Estimados estoy tratando de implementar es fucnion en una base de Access que uso para facturar y no entiendo como hay que cargarla/hacerla funcionar. Si alguien me pudiese ayudar estare muy agradecido. Desde ya muchas gracias. Horacio
Hola amigo espero que me ayuden… tengo una problema kisiera el siguiente script que funciona en MSSQL SERVER 2000 a un script MySQL 5.x:
Create Function dbo.Num2Text(@valor money)
returns varchar(500)
as
begin
declare @textoValor varchar(500)
Select @textoValor = Case when @valor = 0 then ‘CERO’
when @valor = 1 then ‘UN’
when @valor = 2 then ‘DOS’
when @valor = 3 then ‘TRES’
when @valor = 4 then ‘CUATRO’
when @valor = 5 then ‘CINCO’
when @valor = 6 then ‘SEIS’
when @valor = 7 then ‘SIETE’
when @valor = 8 then ‘OCHO’
when @valor = 9 then ‘NUEVE’
when @valor = 10 then ‘DIEZ’
when @valor = 11 then ‘ONCE’
when @valor = 12 then ‘DOCE’
when @valor = 13 then ‘TRECE’
when @valor = 14 then ‘CATORCE’
when @valor = 15 then ‘QUINCE’
when @valor < 20 then 'DIECI' + dbo.Num2Text(@valor - 10) when @valor = 20 then 'VEINTE' when @valor < 30 then 'VEINTI' + dbo.Num2Text(@valor - 20) when @valor = 30 then 'TREINTA' when @valor = 40 then 'CUARENTA' when @valor = 50 then 'CINCUENTA' when @valor = 60 then 'SESENTA' when @valor = 70 then 'SETENTA' when @valor = 80 then 'OCHENTA' when @valor = 90 then 'NOVENTA' when @valor < 100 then dbo.Num2Text(floor(@valor / 10) * 10) + ' Y ' + dbo.Num2Text(@valor % 10) when @valor = 100 then 'CIEN' when @valor < 200 then 'CIENTO ' + dbo.Num2Text(@valor - 100) when @valor in (200, 300, 400, 600, 800) then dbo.Num2Text(floor(@valor / 100)) + 'CIENTOS' when @valor = 500 then 'QUINIENTOS' when @valor = 700 then 'SETECIENTOS' when @valor = 900 then 'NOVECIENTOS' when @valor < 1000 then dbo.Num2Text(floor(@valor / 100) * 100) + ' ' + dbo.Num2Text(@valor % 100) when @valor = 1000 then 'MIL' when @valor < 2000 then 'MIL ' + dbo.Num2Text(@valor % 1000) when @valor < 1000000 then case when @valor % 1000 > 0
then dbo.Num2Text(floor(@valor / 1000)) + ‘ MIL’ + ‘ ‘ + dbo.Num2Text(@valor % 1000)
else dbo.Num2Text(floor(@valor / 1000)) + ‘ MIL’
end
when @valor = 1000000 then ‘UN MILLON’
when @valor < 2000000 then 'UN MILLON ' + dbo.Num2Text(@valor % 1000000) when @valor < 1000000000000.0 then case when (@valor - floor(@valor / 1000000) * 1000000) > 0
then dbo.Num2Text(floor(@valor / 1000000)) + ‘ MILLONES ‘ + dbo.Num2Text(@valor – floor(@valor / 1000000) * 1000000)
else dbo.Num2Text(floor(@valor / 1000000)) + ‘ MILLONES ‘
end
when @valor = 1000000000000.0 then ‘UN BILLON’
when @valor < 2000000000000.0 then 'UN BILLON ' + dbo.Num2Text(@valor - floor(@valor / 1000000000000.0) * 1000000000000.0) else case when (@valor - floor(@valor / 1000000000000.0) * 1000000000000.0) > 0
then dbo.Num2Text(floor(@valor / 1000000000000.0)) + ‘ BILLONES’
else dbo.Num2Text(floor(@valor / 1000000000000.0)) + ‘ BILLONES’ + ‘ ‘ + dbo.Num2Text(@valor – floor(@valor / 1000000000000.0) * 1000000000000.0)
end
end
return(@textoValor)
end
Hola… me encántó esta función y me sirvió de mucho, solo que no sé como eliminar la omisión del “DE” en algunos casos, como UN MILLON “DE” BOLÍVARES”
Gracias… por favor si me pueden ayudar envienme la solución a mi correo electrónico
znoralba@hotmail.com
Gracias nuevamente
alguien me puede decir que debo hacer para que el algoritmo me funcione en excel? gracias lanman_a@hotmail.com
Este codigo de convertir numeros a letras es super a mi me sirvio muchisimo pero estuve tratando de encontrar un forma para que cuado digito 1 me salga uno y no un, pero si cambio case 1 = “uno” lo que son 1´000.000 me saldra uno millones y lo correcto es un millon pero para 1 lo correcto es uno y no un. y ahora tambien lo necesito para pesos y centavos y viend comentarios boy a hacer los cambios para veer si me funcionan.
Este codigo de convertir numeros a letras es super a mi me sirvio muchisimo pero estuve tratando de encontrar un forma para que cuado digito 1 me salga uno y no un, pero si cambio case 1 = “uno” lo que son 1´000.000 me saldra uno millones y lo correcto es un millon pero para 1 lo correcto es uno y no un. y ahora tambien lo necesito para pesos y centavos y viend comentarios boy a hacer los cambios para veer si me funcionan.
Con algunos cambios me sirvió perfecto. Muchas gracias, un código muy útil.
Se le agradece la ayuda de todos.
hola necesito la ayuda sobre este problema en visual .net modo consola en donde ingreso en numero por teclado y arroja el resultado en palabras
desde ya gracias por su ayuda
no entiendo nada es un royooooooooooo
Estimado, si tuvieses la amabilidad de enviarme por mail esta macro, yo hace años que la uso en excel para el tema de los sueldos y las facturas, pero ahora exportamos y a los gringos hay que enviarles todo en inglés, no tengo Vb sólo office XP no sé si con el access pueda cambiar en el código de uno a one y de dos a two, etc.
Muchas gracias de antemano.
ferro.olsoetd@gmail.com
pss yo asi lo hice, para que separara decimales, y me mostrara la palabra pesos y 00/100 M.N.
—-
Private a, b As Double
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
sacardecimal(TextBox1.Text)
If b = 0 Then
TextBox2.Text = Num2Text(a) & ” PESOS” & ” 00/100 M.N.”
Else
TextBox2.Text = Num2Text(a) & ” PESOS” & ” ” & b & “/100 M.N.”
End If
End Sub
Public Sub sacardecimal(ByVal value As String)
Dim ente, valor, c As String
Dim deci
ente = “” : valor = “”
For i As Integer = 1 To Len(value)
c = Mid(value, i, 1)
If c = “.” Then
deci = Split(value, “.”)
b = deci(1)
GoTo 1
Else
valor = valor & c
End If
Next
b = 0
1: a = valor
End Sub
necesito para que en una factura, me salga tambien el importe en letra esto es un ejemplo de lo que quiero:
Importe: 345,65 y en letra debe decir:
TRESCIENTAS CUARENTA Y CINCO CON SESENTA Y CINCO CENTIMOS, si hay alguien y me dice como ponerlo.
necesito para que en una factura, me salga tambien el importe en letra esto es un ejemplo de lo que quiero:
Importe: 345,65 y en letra debe decir:
TRESCIENTAS CUARENTA Y CINCO CON SESENTA Y CINCO CENTIMOS, si hay alguien y me dice como ponerlo.
Hola quisiera saber bien que hacen las lineas que tienen el operador Mod. GRacias x su aporte
Hola! esta muy bien el codigo
Pero podría alguien decirme como lo aplico en matlab
Gracias!!!!!!!
como convertir los numeros 100001001001
30000003030000030
2005724568903
285401123456789107645
GRACIAS POR EL APORTE, LO MEJOR QUE ENCONTRE A COMPARACION DE OTRAS PAGINAS
cual es el valor en numero de la letra a
aqui les dejo el codigo para poner en modo consola ya que vi que algunos tenian esa inquietud:
’24. Cree un programa que lea un numero y muestre en pantalla en numero y letra
Module Module1
Sub Main()
Dim n As Integer
Console.WriteLine(“ingrese n”)
n = Console.ReadLine
Console.WriteLine(Num2Text(n))
Console.ReadLine()
End Sub
Public Function Num2Text(ByVal value As Double) As String
Select Case value
Case 0 : Num2Text = “CERO”
Case 1 : Num2Text = “UN”
Case 2 : Num2Text = “DOS”
Case 3 : Num2Text = “TRES”
Case 4 : Num2Text = “CUATRO”
Case 5 : Num2Text = “CINCO”
Case 6 : Num2Text = “SEIS”
Case 7 : Num2Text = “SIETE”
Case 8 : Num2Text = “OCHO”
Case 9 : Num2Text = “NUEVE”
Case 10 : Num2Text = “DIEZ”
Case 11 : Num2Text = “ONCE”
Case 12 : Num2Text = “DOCE”
Case 13 : Num2Text = “TRECE”
Case 14 : Num2Text = “CATORCE”
Case 15 : Num2Text = “QUINCE”
Case Is < 20 : Num2Text = "DIECI" & Num2Text(value - 10) Case 20 : Num2Text = "VEINTE" Case Is < 30 : Num2Text = "VEINTI" & Num2Text(value - 20) Case 30 : Num2Text = "TREINTA" Case 40 : Num2Text = "CUARENTA" Case 50 : Num2Text = "CINCUENTA" Case 60 : Num2Text = "SESENTA" Case 70 : Num2Text = "SETENTA" Case 80 : Num2Text = "OCHENTA" Case 90 : Num2Text = "NOVENTA" Case Is < 100 : Num2Text = Num2Text(Int(value \ 10) * 10) & " Y " & Num2Text(value Mod 10) Case 100 : Num2Text = "CIEN" Case Is < 200 : Num2Text = "CIENTO " & Num2Text(value - 100) Case 200, 300, 400, 600, 800 : Num2Text = Num2Text(Int(value \ 100)) & "CIENTOS" Case 500 : Num2Text = "QUINIENTOS" Case 700 : Num2Text = "SETECIENTOS" Case 900 : Num2Text = "NOVECIENTOS" Case Is < 1000 : Num2Text = Num2Text(Int(value \ 100) * 100) & " " & Num2Text(value Mod 100) Case 1000 : Num2Text = "MIL" Case Is < 2000 : Num2Text = "MIL " & Num2Text(value Mod 1000) Case Is < 1000000 : Num2Text = Num2Text(Int(value \ 1000)) & " MIL" If value Mod 1000 Then Num2Text = Num2Text & " " & Num2Text(value Mod 1000) Case 1000000 : Num2Text = "UN MILLON" Case Is < 2000000 : Num2Text = "UN MILLON " & Num2Text(value Mod 1000000) Case Is < 1000000000000.0# : Num2Text = Num2Text(Int(value / 1000000)) & " MILLONES " If (value - Int(value / 1000000) * 1000000) Then Num2Text = Num2Text & " " & Num2Text(value - Int(value / 1000000) * 1000000) Case 1000000000000.0# : Num2Text = "UN BILLON" Case Is < 2000000000000.0# : Num2Text = "UN BILLON " & Num2Text(value - Int(value / 1000000000000.0#) * 1000000000000.0#) Case Else : Num2Text = Num2Text(Int(value / 1000000000000.0#)) & " BILLONES" If (value - Int(value / 1000000000000.0#) * 1000000000000.0#) Then Num2Text = Num2Text & " " & Num2Text(value - Int(value / 1000000000000.0#) * 1000000000000.0#) End Select End Function End Module
Como puedo convertir numeros a letras en ACcess para los importes de una factura.
Gracias
¡¡¡Super!!! D.T.B. gracias también victor.
Saludos . .
HOLA BUEN DIA TENGO UN ABASE DE DATOS EN DONDE HICE UN INFORME QUE ME MUSTRA LA FACTURA Y EL IMPORTE CON NUMERO PERO QUIEREO CON LETRA TAMBIEN, YA PEGUE EL CODIGO EN UN MODULO AHORA QUE SIGUE PARA QUE ME DE EL RESULTADO EN LETRA????
A RIKOLO: en tu tabla debes de crear un campo que acepte texto luego de haberlo colocado en tu formulario indicale pormedio de un evento que despues que la etiqueta “supongo” creada se actualice que tu campo de texto nuevo tambien se actualice. ejemplo.
valor_letras=textoletras. de esta manera quedara guardado en el registro y podras verlo en un informe si necesidad de hacer la formula.
UNA PREGUNTA PUEDEN ESPECIFICAR DONDE VAN LOS CODIGOS PARA PODER EJECUTARLO SI FUERA POSIBLE ..LES DEJO MI MSN SI PUEDEN ME LO MANDAN AI PORFA SE LOS AGRADECERIA MUCHO…gersonn_12@hotmail.com……gracias..
Gracias, por el codigo es genial, me haver ayudado mucho…. Mil Gracias..
dioooooos por fin alguien que me ayudo!
Se agradece me sirvio mucho
UNA PREGUNTA SOY NUEVO Y TENGO Q HACER ESTE PROYECTO COMO EXAMEN PUEDEN ESPECIFICAR DONDE VAN LOS CODIGOS PARA PODER EJECUTARLO SI FUERA POSIBLE ..LES DEJO MI MSN SI PUEDEN ME LO MANDAN AI PORFA SE LOS AGRADECERIA MUCHISIMO …sergcomp@hotmail.com……gracias..
excelente función….muchisimas gracias…me saco de un gran apuro ya que necesitaba imprimir facturas con el monto en palabras….
hola me parece excelente el codigo, pudieran apoyarme en lo siguiente:
necesito un web service asp.net que una vez que se le envie el valor monetario este devuelva la cantidad en letra incluyendo los centavos al final con el sig. formato XX/100 M.N. y al ultimo la leyenda pesos
Gracias a todo su equipo de trabajo
mgl_lightning@hotmail.com
Muchas gracias por el aporte me ayudo bastante
Hola sandropatricio, utilice el codigo de tu comentario y funciona muy bien, solo tengo un problema con el UNO, POR EJM.:
El Numero: 161,221.85
Lo escribe así: ciento sesenta y uno mil doscientos veintiuno con 85/100 nuevos soles
Lo correcto sería: ciento sesenta y un mil doscientos veintiuno con 85/100 nuevos soles
Te doy otro ejm.
El Numero: 1,221,121,161,221.38
Lo escribe asi:
UN BILLON DOSCIENTOS VEINTIUNO MIL CIENTO VEINTIUNO MILLONES CIENTO SESENTA Y UNO MIL DOSCIENTOS VEINTIUNO CON 38/100 NUEVOS SOLES
Lo correcto sería:
UN BILLON DOSCIENTOS VEINTIUN MIL CIENTO VEINTIUN MILLONES CIENTO SESENTA Y UN MIL DOSCIENTOS VEINTIUNO CON 38/100 NUEVOS SOLES
Te agradeceria muchisimo si me detallas como corregir estos pequeños detalles
gracias de antemano
Atte.
Juan Jose Regalado Inga
email: jotajota381@hotmail.com
plz … me podriAn recomendar un libro el cual me enseñe a programar desde cosas basicas … porfa recien estoy comenzando a programar se los agradeceria mucho gracias 🙂 🙂
soy nueva en programscion, tengo VB 6,3 no coorre siempre me envia un error de coompilacion se esperaba end sub
El codigo se podria arreglar para algunas situaciones en donde deberia decir UNO en vez de UN. El llamado a la funcion seria el mismo, ya por dentro el codigo analiza cuando debe ser UN o UNO.
Public Function Num2Text(ByVal value As Double, Optional bandera as Integer = 0) As String
Select Case value
Case 0 : Num2Text = “CERO”
Case 1 : If bandera = 0 then Num2Text = “UNO” else Num2Text = “UN”
Case 2 : Num2Text = “DOS”
Case 3 : Num2Text = “TRES”
Case 4 : Num2Text = “CUATRO”
Case 5 : Num2Text = “CINCO”
Case 6 : Num2Text = “SEIS”
Case 7 : Num2Text = “SIETE”
Case 8 : Num2Text = “OCHO”
Case 9 : Num2Text = “NUEVE”
Case 10 : Num2Text = “DIEZ”
Case 11 : Num2Text = “ONCE”
Case 12 : Num2Text = “DOCE”
Case 13 : Num2Text = “TRECE”
Case 14 : Num2Text = “CATORCE”
Case 15 : Num2Text = “QUINCE”
Case Is < 20 : Num2Text = "DIECI" & Num2Text(value - 10, bandera) Case 20 : Num2Text = "VEINTE" Case Is < 30 : Num2Text = "VEINTI" & Num2Text(value - 20, bandera) Case 30 : Num2Text = "TREINTA" Case 40 : Num2Text = "CUARENTA" Case 50 : Num2Text = "CINCUENTA" Case 60 : Num2Text = "SESENTA" Case 70 : Num2Text = "SETENTA" Case 80 : Num2Text = "OCHENTA" Case 90 : Num2Text = "NOVENTA" Case Is < 100 : Num2Text = Num2Text(Int(value \ 10) * 10, bandera) & " Y " & Num2Text(value Mod 10, bandera) Case 100 : Num2Text = "CIEN" Case Is < 200 : Num2Text = "CIENTO " & Num2Text(value - 100, bandera) Case 200, 300, 400, 600, 800 : Num2Text = Num2Text(Int(value \ 100), bandera) & "CIENTOS" Case 500 : Num2Text = "QUINIENTOS" Case 700 : Num2Text = "SETECIENTOS" Case 900 : Num2Text = "NOVECIENTOS" Case Is < 1000 : Num2Text = Num2Text(Int(value \ 100) * 100, bandera) & " " & Num2Text(value Mod 100, bandera) Case 1000 : Num2Text = "MIL" Case Is < 2000 : Num2Text = "MIL " & Num2Text(value Mod 1000) Case Is < 1000000 : Num2Text = Num2Text(Int(value \ 1000), 1) & " MIL" If value Mod 1000 Then Num2Text = Num2Text & " " & Num2Text(value Mod 1000) Case 1000000 : Num2Text = "UN MILLON" Case Is < 2000000 : Num2Text = "UN MILLON " & Num2Text(value Mod 1000000) Case Is < 1000000000000.0# : Num2Text = Num2Text(Int(value / 1000000), 1) & " MILLONES " If (value - Int(value / 1000000) * 1000000) Then Num2Text = Num2Text & " " & Num2Text(value - Int(value / 1000000) * 1000000, 1) Case 1000000000000.0# : Num2Text = "UN BILLON" Case Is < 2000000000000.0# : Num2Text = "UN BILLON " & Num2Text(value - Int(value / 1000000000000.0#) * 1000000000000.0#) Case Else : Num2Text = Num2Text(Int(value / 1000000000000.0#), 1) & " BILLONES" If (value - Int(value / 1000000000000.0#) * 1000000000000.0#) Then Num2Text = Num2Text & " " & Num2Text(value - Int(value / 1000000000000.0#) * 1000000000000.0#) End Select End Function
oigan soi nuevo en esto pueden hacer el diseño tbm por fa
Definitivamente Excelente
TextBox2.Text = Num2Text(TextBox1.Text) & ” PESOS”
poner dentro de “” Pesos, Bolivares, Dolares
para alguien que necesite una sola moneda.
Muchas Gracias
No pasa nada, me pase 10 horas intentando y todo es una basura.
no existe formulas de conversion de numeros a letras.
The code a little bit revised :
Public Function spellNumber(ByVal numString As String) As String
Dim validString As System.Text.RegularExpressions.Match = System.Text.RegularExpressions.Regex.Match(numString, “[0-9]*\.?[0-9]+”) ‘validate numString
Try
Dim dNum As Double = Convert.ToDouble(validString.ToString) ‘convert validString to double
Dim iInt As Int64 = Convert.ToInt64(Math.Truncate(dNum)) ‘get integer part of dNum
Dim iDec As Integer = Convert.ToInt32(Math.Round((dNum – iInt) * 100, 2)) ‘get decimal part of dNum
Dim result As String = num2Text(iInt) ‘convert num to text
Select Case iInt ‘format output
Case 1 : result &= ” PESO ”
Case Is < 1000000 : result &= " PESOS " Case Is >= 1000000 : If ((iInt Mod 1000000) \ 1000 = 0) AndAlso (iInt Mod 1000 = 0) Then result &= ” DE PESOS ” Else result &= ” PESOS ” ‘if iInt >= 1 million and thousands = 0 and pesos = 0
End Select
result &= iDec.ToString & “/100 M.N.” ‘add decimal part
Return result
Catch ex As Exception
errHandler(ex)
Return estr
Finally
If validString IsNot Nothing Then validString = Nothing
End Try
End Function
Private Function num2Text(ByVal num As Int64) As String
Dim sUnits() As String = {“CERO”, “UN”, “DOS”, “TRES”, “CUATRO”, “CINCO”, “SEIS”, “SIETE”, “OCHO”, “NUEVE”, “DIEZ”, “ONCE”, “DOCE”, “TRECE”, “CATORCE”, “QUINCE”}
Dim sTens() As String = {“”, “VEINTE”, “TREINTA”, “CUARENTA”, “CINCUENTA”, “SESENTA”, “SETENTA”, “OCHENTA”, “NOVENTA”}
Dim sHundreds() As String = {“CIENTO”, “DOSCIENTOS”, “TRESCIENTOS”, “CUATROCIENTOS”, “QUINIENTOS”, “SEISCIENTOS”, “SETECIENTOS”, “OCHOCIENTOS”, “NOVECIENTOS”}
Dim oneMillion As Integer = 1000000 : Dim twoMillion As Integer = 2000000 : Dim oneBillion As Int64 = 1000000000 : Dim twoBillion As Int64 = 2000000000
Select Case num
Case 0 To 15 : num2Text = sUnits(num)
Case 16 To 19 : num2Text = “DIECI” & sUnits(num – 10)
Case 21 To 29 : num2Text = “VEINTI” & sUnits(num – 20)
Case 20, 30, 40, 50, 60, 70, 80, 90 : num2Text = sTens(num \ 10 – 1)
Case Is < 100 : num2Text = sTens(num \ 10 - 1) & " Y " & sUnits(num Mod 10) Case 100 : num2Text = "CIEN" Case Is < 200 : num2Text = "CIENTO " & num2Text(num - 100) Case 200, 300, 400, 500, 600, 700, 800, 900 : num2Text = sHundreds(num \ 100 - 1) Case Is < 1000 : num2Text = sHundreds(num \ 100 - 1) & " " & num2Text(num Mod 100) Case 1000 : num2Text = "MIL" Case Is < 2000 : num2Text = "MIL " & num2Text(num Mod 1000) Case Is < oneMillion : num2Text = num2Text(num \ 1000) & " MIL" : If num Mod 1000 Then num2Text = num2Text & " " & num2Text(num Mod 1000) Case oneMillion : num2Text = "UN MILLON" Case Is < twoMillion : num2Text = "UN MILLON " & num2Text(num Mod oneMillion) Case Is < oneBillion : num2Text = num2Text(num \ oneMillion) & " MILLONES" : If (num - (num \ oneMillion) * oneMillion) Then num2Text = num2Text & " " & num2Text(num - (num \ oneMillion) * oneMillion) Case oneBillion : num2Text = "UN BILLON" Case Is < twoBillion : num2Text = "UN BILLON " & num2Text(num - (num \ oneBillion) * oneBillion) Case Else : num2Text = num2Text(num \ oneBillion) & " BILLONES" : If (num - (num \ oneBillion) * oneBillion) Then num2Text = num2Text & " " & num2Text(num - (num \ oneBillion) * oneBillion) End Select End Function
COMO C CUAL ES EL TEXTBOX DONDE TENGO EL NUMERO Y COMO SE CUAL ES DODNE SE VA ESCRIBIR CON LETARA Y COMO SE VA APLICAR ESTE CODIFGO MEDIANTE CLIC MEDIANTE UN BOTON
GRACIAS
_==D xD
me pueden explicar paso a paso como usar toda esa codificacion,
1 copiar el codigo pegar lo un modulo (debo guardar algo, salvar, darle nombre, que nombre)
2 en el formulario tengo dos tex box donde escribo el numero y otro donde quiero que aparesca el texto
3 como relaciono todo eso codigo con los controles del formulario
HOLA EL METODO ESTA EXCELENTE SOLO QUE CUNADO ES CON DECIMALES SE CAE, POR UN VALOR FUERA DE RANGO, SOLO FUCIONA PARA NUMERO ENTEROS O Q TERMINEN EN .00
Buen codigo Graciass!!!!!
tan pendejos
pongan las fotos de su hermana
use el ded select case is < 20 y no funciono
I opine that to receive the mortgage loans from banks you ought to present a great motivation. Nevertheless, once I have got a term loan, because I was willing to buy a car.
sera que laguien tiene el codigo para java script
ola a todos estan muy exelente losprogramas pero me podrian hechar un mano es que el program que necesito va con una finalidad es hacerlos con punteros…..se les agradece si me dan la idea …:)
Hola a todos muy buenas aportaciones.
Yo necesito Ayuda ya que estoy programando en Asp.Net y al parecer nadie a subido nada sobre eso, espero me puedan resolver.
De Antemano Gracias
Hola amigos quisiera pedirles el favor es que tengo un taller de algoritmos y pues me piden convertir un valor en pesos y pasarlo a letras como hago?
I think that to receive the personal loans from creditors you ought to have a firm motivation. However, one time I’ve received a sba loan, just because I wanted to buy a building.
When you’re in uncomfortable position and have got no cash to move out from that point, you will need to take the home loans. Just because that would help you emphatically. I get student loan every year and feel OK because of it.
Hola Disculpa la pregunta pero el codigo no me funciona ya que yo estoy haciendo el programa desde un Comand Buton y cada que escribo el FUNCTION men cambia de End Sub a End Function y no se como lo puedo hacer porfa ayudame ya que me sirve este codigo
Muy bueno el post, me sirvio mucho para algo en mi trabajo, de igual forma tener presente validar cuando sea un numero negativo-
bueno la verdad esto de los codigos me esta confundiento en el armado del formulario asi q sia lguien puede q publique la imgen de su formulario y el codigo fuente si no fuera mucha molestia
Do you acknowledge that it’s correct time to get the home loans, which will make your dreams come true.
GRACIAS MUY, MUY ÚTIL…. Y MUY SENCILLO….
Acá hay una función que convierte números a letras con decimales y hasta miles de billones.
http://vba-para-excel.blogspot.com/2011/08/convertir-numeros-letras-con-decimales.html
Soy un inepto no se como hacer esto. Ayudenme por favor
tengo una tabla que se llama tabla1 con los siguientes campos:
Id
Numero
Letras
y un formulario que se llama Tabla1 con los mismos campos
me voy al formulario y lo veo en vista diseño
luego selecciono el campo letras y en propiedades selecciono Eventos al perder enfoque generador de codigos
y le pego el primer codigod de esta hoja web
luego cuando entro al formulario y escribo un mumero y voy al otro campo y luego perde enfoque me da el mensaje “error en compilacion” se esperaba end sub
por favor ayudemne.
If you’re in a not good position and have no money to get out from that, you will require to receive the loans. Because it will aid you emphatically. I take auto loan every single year and feel myself OK just because of it.
Excelente funcion, muil gracias a todos los foristas esta gente es la que cambia el mundo
Exelente amigos gracias por los ejemplos funciono muy bien son lo máximo..!! Suerte bendiciones
necesito ayuda con sto: si me podrias ayudar necesito traducir un numero de una fecha x ejemplo .. 12, 2, 2001 y que el programa me ponga 12 febrero 2001 tengo todo el programa hecho menos eso…
sbien ese codigo uni de lo mas pequeño y claro vale vale la pena
Para que funcione tienen que crear el siguiente formulario o diseño
————————————————-|
Nombre del formulario — [] x |
————————————————-|
TextBox1 Botton |
|
Label1 |
————————————————-|
y colocan el siguente codigo en el evento del boton
Dim letras As Integer
Dim conversion As String
letras = TextBox1.Text
conversion = Num2Text(letras)
Label1.Text = conversion
Excelente aportación. Gracias por la ayuda
aca les dejo el algoritmo URL: convetirnumerosaletras.blogspot.com/2013/02/algoritmo.html, mi correo es kelcom11@hotmail.com
Muy buen codigo, me sirvio en un proyecto uregente que lo requeria para la impresión de cheques. Muchas Gracias por el codigo.
Jhonny, como puedo convertir numeros a letras en Access 2007, no se poner la instruccion en el campo. Ejemplo: ConLetra ( ), tenco un campo que me suma la el Subtotal mas IVA y el numero resultante quiero que aparesca en letras, si no es mucha molestia te dejo mi E-Mail jala_478@yahoo.com.mx
Gracias de antemano.
Jhonny, como puedo convertir numeros a letras en Access 2007, no se poner la instruccion en el campo. Ejemplo: ConLetra ( ), tenco un campo que me suma la el Subtotal mas IVA y el numero resultante quiero que aparesca en letras, si no es mucha molestia te dejo mi E-Mail jala_478@yahoo.com.mx
Gracias de antemano.
Da error con algunos numeros, por ejemplo: 43379.59
Muchisimas gracias, me sirvio mucho, Saludos desde Tijuana Mexico