Welcome to Scribd, the world's digital library. Read, publish, and share books and documents. See more
Standard view
Full view
of .
0 of .
Results for:
P. 1
Convertir números a Palabras

# Convertir números a Palabras

Ratings: (0)|Views: 984|Likes:
archivo de la nota Como convertir números en palabras en Excel en Español
archivo de la nota Como convertir números en palabras en Excel en Español

### Availability:

See more
See less

03/18/2014

pdf

text

original

option explicit

'********************************************************
'*******************************************************
'****************
' main function *
'****************

function spellnumber(byval mynumber, sep, mon)
dim dollars, cents, temp
dim decimalplace, count

redim place(9) as string
place(2) = " mil "
place(3) = " mill\u00f3n "
place(4) = " bill\u00f3n "
place(5) = " trill\u00f3n "

' string representation of amount.
mynumber = trim(cstr(mynumber))

' position of decimal place 0 if none.
if sep = "." then decimalplace = instr(mynumber, ".")
if sep = "," then decimalplace = instr(mynumber, ",")

' convert cents and set mynumber to currency amount.
if decimalplace > 0 then
cents = gettens(left(mid(mynumber, decimalplace + 1) & _
"00", 2))
mynumber = trim(left(mynumber, decimalplace - 1))
end if
count = 1

do while mynumber <> ""
temp = gethundreds(right(mynumber, 3))
if temp <> "" then dollars = temp & place(count) & dollars
if len(mynumber) > 3 then

mynumber = left(mynumber, len(mynumber) - 3)
else mynumber = ""
end if
count = count + 1
loop
select case dollars
case ""
dollars = "cero " & mon
case "un"
dollars = "un " & left(mon, len(mon) - 1)
case else
dollars = dollars & " " & mon
end select
select case cents
case ""
cents = " con cero centavos"
case "one"
cents = " con un centavo"
case else
cents = " con " & cents & " centavos"
end select
spellnumber = ucase(trim(dollars & cents))
end function

'******************************************* ' converts a number from 100-999 into text * '*******************************************

private function gethundreds(byval mynumber)
dim result as string
if val(mynumber) = 0 then exit function
mynumber = right("000" & mynumber, 3)
' convert the hundreds place.
if mid(mynumber, 1, 1) <> "0" then
select case mid(mynumber, 1, 1)
case 1
select case len(mynumber)
case 1
result = "un "
case 3
result = "ciento "
case 4
result = ""
case 6
result = "ciento "
case 9
result = "ciento "
end select
case 2
result = "doscientos "
case 3
result = "trescientos "
case 4
result = "cuatrocientos "
case 5
result = "quinientos "
case 6
result = "seiscientos "
case 7
result = "setecientos "
case 8
result = "ochocientos "
case 9
result = "novecientos "
end select
end if
' convert the tens and ones place.
if mid(mynumber, 2, 1) <> "0" then
result = result & gettens(mid(mynumber, 2))

elseresult = result & getdigit(mid(mynumber, 3))
end if
gethundreds = result

end function

'********************************************* ' converts a number from 10 to 99 into text. * '*********************************************

private function gettens(tenstext)
dim result as string
result = ""
' null out the temporary function value.
if val(left(tenstext, 1)) = 1 then
' if value between 10-19...

select case val(tenstext)
case 10: result = "diez"
case 11: result = "once"
case 12: result = "doce"
case 13: result = "trece"
case 14: result = "catorce"
case 15: result = "quince"
case 16: result = "diez y seis"
case 17: result = "diez y siete"
case 18: result = "diez y ocho"
case 19: result = "diez y nueve"
case else

end select
else
' if value between 20-99...

select case val(left(tenstext, 1))
case 2: result = "veinti"
case 3: result = "treinta y "
case 4: result = "cuarenta y "
case 5: result = "cincuenta y "
case 6: result = "sesenta y "
case 7: result = "setenta y "
case 8: result = "ochenta y "
case 9: result = "noventa y "
case else

end select
result = result & getdigit _

(right(tenstext, 1)) ' retrieve ones place.
end if
gettens = result

end function

'******************************************* ' converts a number from 1 to 9 into text. * '*******************************************

private function getdigit(digit)
select case val(digit)