• a

  •  

    Abril 2008
    L M X J V S D
    « Mar   May »
     123456
    78910111213
    14151617181920
    21222324252627
    282930  
  • Nube de Categoria

Como convertir números a letras en Visual Basic .NET

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

End Function

Fuente:
Convertir numero en letras

7 comentarios

  1. Vos pero que pasa cuando ingresar solo el numero uno de despliega un.

  2. Gracias por el aporte, a mi si me sirvio

  3. Muchas gracias por esta función, me va a ser muy útil y me ahorrará tiempo de programación.

    Saludos.

  4. hola la verdad soy nueva en este programa despues de este codigo q elementos agrego en el form1 , si alguine podria ayudarme o orientame por favor
    y gracias de antemano

  5. Muchas gracias me fue de mucha ayuda!!!!

  6. Haciendo pruebas encontre la manera de incluir los decimales en el algoritmo es bien sencillo, existen mas formas de hacerlo, eso lo sabemos pero aki esta una para los ke no kieren dar muxas vueltas.

    Function Num2Text(ByVal Value As Decimal) As String
    Dim valores() As String
    Dim valor As String = Value
    Dim entero As Decimal = 0
    Dim fraccion As Decimal = 0

    If valor.Contains(“.”) OrElse valor.Contains(“,”) Then
    valores = Split(valor, “.”)
    Value = CDec(valores(0))

    If valores.Length > 1 Then
    fraccion = CDec(valores(1))
    End If
    End If

    ##Algoritmo ya posteado………

    y al final agregamos lo siguiente.

    If fraccion 0 Then
    Num2Text = Num2Text & ” CON ” & Num2Text(CDec(fraccion))
    End If

    End Function

    Hemos hecho prueba y nos funciona. Cualkier aporte comentario o modificacion sera bueno, para crecer.

    jeje.

Escribe un comentario