by pappawinni » Wed Feb 10, 2010 5:41 pm
i created some function to get numbers in words.
Even if I do not speak spanish I tried to create a function for that also.
I did not do much testing but hope it works.....
- Code: Select all
public function NumberInWordsDE( Number as double ) as string
Dim strNum as string
Dim sglNumber as double
Dim strOut as string
Dim i as integer
Dim intA as integer , intB as integer
Dim intTSeg as integer
Dim strFormat as string
Dim strAppend as string
Dim strZero as string
Dim strLower20(1 to 19) as string
Dim strTenth(1 to 10) as string
Dim strExp3(1 to 4) as string
Dim strOneExt(1 to 4, 1 to 2) as string
Dim strTenthIn as string
Dim strHundIn as string
Dim bolTenthMode as boolean = false
strZero = "Null"
strLower20(1) = "ein"
strLower20(2) = "zwei"
strLower20(3) = "drei"
strLower20(4) = "vier"
strLower20(5) = "fünf"
strLower20(6) = "sechs"
strLower20(7) = "sieben"
strLower20(8) = "acht"
strLower20(9) = "neun"
strLower20(10) = "zehn"
strLower20(11) = "elf"
strLower20(12) = "zwölf"
strLower20(13) = "dreizehn"
strLower20(14) = "vierzehn"
strLower20(15) = "fünfzehn"
strLower20(16) = "sechzehn"
strLower20(17) = "siebzehn"
strLower20(18) = "achtzehn"
strLower20(19) = "neunzehn"
strTenth(1) = "zehn"
strTenth(2) = "zwanzig"
strTenth(3) = "dreissig"
strTenth(4) = "vierzig"
strTenth(5) = "fünfzig"
strTenth(6) = "sechzig"
strTenth(7) = "siebzig"
strTenth(8) = "achtzig"
strTenth(9) = "neunzig"
strTenth(10) = "hundert"
strExp3(1) = "tausend"
strExp3(2) = "million"
strExp3(3) = "milliarde"
strExp3(4) = "billion"
strOneExt(1,1) = "s"
strOneExt(1,2) = ""
strOneExt(2,1) = ""
strOneExt(2,2) = ""
strOneExt(3,1) = "e"
strOneExt(3,2) = "en"
strOneExt(4,1) = "e"
strOneExt(4,2) = "n"
strOneExt(4,1) = "e"
strOneExt(4,2) = "en"
strTenthIn = "und"
strHundIn = ""
strOut = ""
sglNumber = abs(Number)
intTSeg = int(int(log(sglNumber)/log(10))/3+1)
strFormat = fill(strFormat,"#",intTSeg*3) & ".##"
strNum = Format(sglNumber,strFormat," ",True)
if (intTseg > 3) or (intTseg < 1) then
return("???????????????")
exit sub
end if
for i = 1 to intTSeg
strAppend = strOneExt(intTSeg - i + 1, 2)
intA = val(left(strNum,3))
strNum = right(strNum,len(strNum)-3)
if (strOut <> "") and (intA>99) then strOut = strOut & strHundIn
if intA > 99 then strOut = strOut & strLower20(int(intA)/100) & strTenth(10)
intB = intA mod 100
if (strOut <> "") and (intB >0) then strOut = strOut & strHundIn
select intB
case 20 to 99:
if bolTenthMode = True then
strOut = strOut & strTenth(int(intB / 10))
if (intB mod 10) > 0 then strOut = strOut & strTenthIn & strLower20(intB mod 10)
else
if (intB mod 10) > 0 then strOut = strOut & strLower20(intB mod 10) & strTenthIn
strOut = strOut & strTenth(int(intB / 10))
end if
case 2 to 19:
strOut = strOut & strLower20(intB)
case 1:
strOut = strOut & strLower20(intB) & strOneExt(intTSeg - i + 1,1)
strAppend = ""
case 0:
if int(sglNumber)=0 then strOut = strOut & strZero
end select
if ((intTseg - i) > 0) and (intA > 0) then
strOut = strOut & strExp3(intTseg - i) & strAppend
end if
next
strNum = format(val(right(strNum,2)),"#")
if val(strNum)>0 then strOut = strOut & " " & strNum & "/100"
return strOut
end function
public function NumberInWordsEN( Number as double ) as string
Dim strNum as string
Dim sglNumber as double
Dim strOut as string
Dim i as integer
Dim intA as integer , intB as integer
Dim intTSeg as integer
Dim strFormat as string
Dim strAppend as string
Dim strZero as string
Dim strLower20(1 to 19) as string
Dim strTenth(1 to 10) as string
Dim strExp3(1 to 4) as string
Dim strOneExt(1 to 4, 1 to 2) as string
Dim strTenthIn as string
Dim strHundIn as string
Dim bolTenthMode as boolean = true
strZero = "zero"
strLower20(1) = "one "
strLower20(2) = "two "
strLower20(3) = "three "
strLower20(4) = "four "
strLower20(5) = "five "
strLower20(6) = "six "
strLower20(7) = "seven "
strLower20(8) = "eight "
strLower20(9) = "nine "
strLower20(10) = "ten "
strLower20(11) = "eleven "
strLower20(12) = "twelve "
strLower20(13) = "thirteen "
strLower20(14) = "fourteen "
strLower20(15) = "fifteen "
strLower20(16) = "sixteen "
strLower20(17) = "seventeen "
strLower20(18) = "eighteen "
strLower20(19) = "nineteen "
strTenth(1) = "ten"
strTenth(2) = "twenty"
strTenth(3) = "thirty"
strTenth(4) = "forty"
strTenth(5) = "fifty"
strTenth(6) = "sixty"
strTenth(7) = "seventy"
strTenth(8) = "eighty"
strTenth(9) = "ninety"
strTenth(10) = "hundred"
strExp3(1) = "thousand"
strExp3(2) = "million"
strExp3(3) = "billion"
strExp3(4) = "trillion"
strOneExt(1,1) = ""
strOneExt(1,2) = ""
strOneExt(2,1) = ""
strOneExt(2,2) = ""
strOneExt(3,1) = ""
strOneExt(3,2) = ""
strOneExt(4,1) = ""
strOneExt(4,2) = ""
strOneExt(4,1) = ""
strOneExt(4,2) = ""
strTenthIn = "-"
strHundIn = " and "
strOut = ""
sglNumber = abs(Number)
intTSeg = int(int(log(sglNumber)/log(10))/3+1)
strFormat = fill(strFormat,"#",intTSeg*3) & ".##"
strNum = Format(sglNumber,strFormat," ",True)
if (intTseg > 3) or (intTseg < 1) then
return("???????????????")
exit sub
end if
for i = 1 to intTSeg
strAppend = strOneExt(intTSeg - i + 1, 2)
intA = val(left(strNum,3))
strNum = right(strNum,len(strNum)-3)
if (strOut <> "") and (intA>99) then strOut = strOut & strHundIn
if intA > 99 then strOut = strOut & strLower20(int(intA)/100) & strTenth(10)
intB = intA mod 100
if (strOut <> "") and (intB >0) then strOut = strOut & strHundIn
select intB
case 20 to 99:
if bolTenthMode = True then
strOut = strOut & strTenth(int(intB / 10))
if (intB mod 10) > 0 then strOut = strOut & strTenthIn & strLower20(intB mod 10)
else
if (intB mod 10) > 0 then strOut = strOut & strLower20(intB mod 10) & strTenthIn
strOut = strOut & strTenth(int(intB / 10))
end if
case 2 to 19:
strOut = strOut & strLower20(intB)
case 1:
strOut = strOut & strLower20(intB) & strOneExt(intTSeg - i + 1,1)
strAppend = ""
case 0:
if int(sglNumber)=0 then strOut = strOut & strZero
end select
if ((intTseg - i) > 0) and (intA > 0) then
strOut = strOut & strExp3(intTseg - i) & strAppend
end if
next
strNum = format(val(right(strNum,2)),"#")
if val(strNum)>0 then strOut = strOut & " " & strNum & "/100"
return strOut
end function
public function NumberInWordsESP( Number as double ) as string
Dim strNum as string
Dim sglNumber as double
Dim strOut as string
Dim i as integer
Dim intA as integer , intB as integer
Dim intTSeg as integer
Dim strFormat as string
Dim strAppend as string
Dim strZero as string
Dim strLower20(1 to 29) as string
Dim strTenth(1 to 10) as string
Dim strExp3(1 to 4) as string
Dim strOneExt(1 to 4, 1 to 2) as string
Dim strTenthIn as string
Dim strHundIn as string
Dim bolTenthMode as boolean = true
strZero = "cero"
strLower20(1) = "un "
strLower20(2) = "dos "
strLower20(3) = "tres "
strLower20(4) = "cuatro "
strLower20(5) = "cinco "
strLower20(6) = "seis "
strLower20(7) = "siete "
strLower20(8) = "ocho "
strLower20(9) = "nueve "
strLower20(10) = "diez "
strLower20(11) = "once "
strLower20(12) = "doce "
strLower20(13) = "trece "
strLower20(14) = "catorce "
strLower20(15) = "quince "
strLower20(16) = "dieciseis "
strLower20(17) = "diecisiete "
strLower20(18) = "dieciocho "
strLower20(19) = "diecinueve "
strLower20(20) = "veinte "
strLower20(21) = "veintiuno "
strLower20(22) = "veintidos "
strLower20(23) = "veintitres "
strLower20(24) = "veinticuatro "
strLower20(25) = "veinticinco "
strLower20(26) = "veintiseis "
strLower20(27) = "veintisiete "
strLower20(28) = "veintiocho "
strLower20(29) = "veintinueve "
strLower20(10) = "diez "
strLower20(11) = "once "
strLower20(12) = "doce "
strLower20(13) = "trece "
strLower20(14) = "catorce "
strLower20(15) = "quince "
strLower20(16) = "dieciseis "
strLower20(17) = "diecisiete "
strLower20(18) = "dieciocho "
strLower20(19) = "diecinueve "
strTenth(1) = "diez"
strTenth(2) = "veinte"
strTenth(3) = "treinta"
strTenth(4) = "cuarenta"
strTenth(5) = "cincuenta"
strTenth(6) = "sesenta"
strTenth(7) = "setenta"
strTenth(8) = "ochenta"
strTenth(9) = "noventa"
strTenth(10) = "cien"
strExp3(1) = "mil"
strExp3(2) = "million"
strExp3(3) = "mil milliones"
strExp3(4) = "billion"
strOneExt(1,1) = "o "
strOneExt(1,2) = ""
strOneExt(2,1) = " "
strOneExt(2,2) = ""
strOneExt(3,1) = " "
strOneExt(3,2) = "es"
strOneExt(4,1) = " "
strOneExt(4,2) = ""
strOneExt(4,1) = " "
strOneExt(4,2) = "es"
strTenthIn = " y "
strHundIn = " "
strOut = ""
sglNumber = abs(Number)
intTSeg = int(int(log(sglNumber)/log(10))/3+1)
strFormat = fill(strFormat,"#",intTSeg*3) & ".##"
strNum = Format(sglNumber,strFormat," ",True)
if (intTseg > 3) or (intTseg < 1) then
return("???????????????")
exit sub
end if
for i = 1 to intTSeg
strAppend = strOneExt(intTSeg - i + 1, 2)
intA = val(left(strNum,3))
strNum = right(strNum,len(strNum)-3)
if (strOut <> "") and (intA>99) then strOut = strOut & strHundIn
if intA > 99 then strOut = strOut & strLower20(int(intA)/100) & strTenth(10)
intB = intA mod 100
if (strOut <> "") and (intB >0) then strOut = strOut & strHundIn
select intB
case 30 to 99:
if bolTenthMode = True then
strOut = strOut & strTenth(int(intB / 10))
if (intB mod 10) > 0 then strOut = strOut & strTenthIn & strLower20(intB mod 10)
else
if (intB mod 10) > 0 then strOut = strOut & strLower20(intB mod 10) & strTenthIn
strOut = strOut & strTenth(int(intB / 10))
end if
case 2 to 29:
strOut = strOut & strLower20(intB)
case 1:
strOut = strOut & trim(strLower20(intB)) & strOneExt(intTSeg - i + 1,1)
strAppend = ""
case 0:
if int(sglNumber)=0 then strOut = strOut & strZero
end select
if ((intTseg - i) > 0) and (intA > 0) then
strOut = strOut & strExp3(intTseg - i) & strAppend
end if
next
strNum = format(val(right(strNum,2)),"#")
if val(strNum)>0 then strOut = strOut & " " & strNum & "/100"
return strOut
end function
Dim sglA as double
for i as integer = 1145025 to 1145035
sglA = i + 0.21
print( sglA )
print( NumberInWordsEN(sglA) )
print( NumberInWordsDE(sglA) )
print( NumberInWordsESP(sglA) )
next
Last edited by
pappawinni on Thu Feb 11, 2010 6:34 pm, edited 3 times in total.
Pappa makes everything what otherwise none likes
![Smile :)](images/smilies/icon_e_smile.gif)