# Number to Word Convertion

Converts Number into words up to 999 trillion. It is a simple short code.

**Original Author:** Opal Raj Ghimire

### Code

`Number to words, fairly small code`

Opal R. Ghimire, Kathmandu, email:buna48@hotmail.com

?á

'THIS FUNCTION CONVERTS 1 TO 999 TRILLION INTO WORDS

Public Function ToWords(Num

As String) As String

Dim sFormated As String, Unit

As String, Ans(5) As String

Dim K As Integer, K1

As Integer

Ans(0) = "trillion ": Ans(1) = "billion ": Ans(2) = "million "

Ans(3) =

"thousand ": Ans(4) = ""

sFormated = Format(Num, "000000000000000.00")

For K = 1 To 13

Step 3

?á?á?á

Unit = Mid$(sFormated, K, 3)

?á?á?á If Val(Unit) > 0 Then ToWords = ToWords + ToNum(Unit) + Ans(K1)

?á?á?á

K1 = K1 + 1

Next

'HANDLES DECIMAL PARTS (IF ANY)

If Val(Num) - Int(Num) <> 0

Then ToWords = ToWords + "and " +

Right$(sFormated, 2) +

"/100"

End Function

'THIS FUNCTION CONVERTS 1 TO 999 INTO WORDS

Public Function ToNum(Num As String)

As String

Dim N(19) As String, NN(8)

As String, Formated As String

Dim Hun As Integer, Tens

As Integer

N(0) = "": N(1) = "one": N(2) = "two": N(3) = "three": N(4) = "four": N(5) =

"five": N(6) = "six": N(7) = "seven": N(8) = "eight": N(9) = "nine": N(10) =

"ten": N(11) = "eleven"

N(12) = "twelve": N(13) = "thirteen": N(14) = "fourteen": N(15) = "fifteen":

N(16) = "sixteen": N(17) = "seventeen": N(18) = "eighteen": N(19) = "nineteen"

NN(0) = "twenty": NN(1) = "thirty": NN(2) = "forty": NN(3) = "fifty": NN(4) =

"sixty": NN(5) = "seventy": NN(6) = "eighty": NN(7) = "ninety"

Formated = Format(Num, "000.00")

Hun = Mid$(Formated, 1, 1)

Tens = Mid$(Formated, 2, 2)

If Hun <> 0 Then ToNum = N(Hun) + " hundred "

If Tens <> 0 Then

?á?á?á If Tens < 20 Then

?á?á?á?á?á?á?á

ToNum = ToNum + N(Tens) + " "

?á?á?á Else '>20

?á?á?á?á?á?á?á

ToNum = ToNum + NN(Mid(Tens, 1, 1) - 2) + " " + N(Mid(Tens, 2, 1)) + " "

?á?á?á End If

End If 'Tens <> 0

End Function

Loading Comments ...

## Comments

No comments have been added for this post.

*You must be logged in to make a comment.*