Numbers to Words in hundred and Millions

Asked By 0 points N/A Posted on -
qa-featured

Hi,

I have copied the following code from this site, it's working properly, but it converts numbers in the thousands and Lakhs. I need the same code to be converted numbers to Hundreds, Millions and Billions format. Can someone Help me in this regard? Thanks in advance.

Function Ntow(amt As Variant) As Variant

Dim FIGURE As Variant

Dim LENFIG As Integer

Dim i As Integer

Dim WORDs(19) As String

Dim tens(9) As String

WORDs(1) = "One"

WORDs(2) = "Two"

WORDs(3) = "Three"

WORDs(4) = "Four"

WORDs(5) = "Five"

WORDs(6) = "Six"

WORDs(7) = "Seven"

WORDs(8) = "Eight"

WORDs(9) = "Nine"

WORDs(10) = "Ten"

WORDs(11) = "Eleven"

WORDs(12) = "Twelve"

WORDs(13) = "Thirteen"

WORDs(14) = "Fourteen"

WORDs(15) = "Fifteen"

WORDs(16) = "Sixteen"

WORDs(17) = "Seventeen"

WORDs(18) = "Eighteen"

WORDs(19) = "Nineteen"

tens(2) = "Twenty"

tens(3) = "Thirty"

tens(4) = "Forty"

tens(5) = "Fifty"

tens(6) = "Sixty"

tens(7) = "Seventy"

tens(8) = "Eighty"

tens(9) = "Ninety" FIGURE = amt FIGURE = Format(FIGURE, "FIXED")

FIGLEN = Len(FIGURE) If FIGLEN < 12 Then FIGURE = Space(12 – FIGLEN) & FIGURE End If If Val(Left(FIGURE, 9)) > 1 Then Ntow = "SAR " ElseIf Val(Left(FIGURE, 9)) = 1 Then Ntow = "SAR " End If For i = 1 To 3 If Val(Left(FIGURE, 2)) < 20 And Val(Left(FIGURE, 2)) > 0 Then Ntow = Ntow & WORDs(Val(Left(FIGURE, 2))) ElseIf Val(Left(FIGURE, 2)) > 19 Then Ntow = Ntow & tens(Val(Left(FIGURE, 1))) Ntow = Ntow & WORDs(Val(Right(Left(FIGURE, 2), 1))) End If If i = 1 And Val(Left(FIGURE, 2)) > 0 Then Ntow = Ntow & " Crore " ElseIf i = 2 And Val(Left(FIGURE, 2)) > 0 Then Ntow = Ntow & " Lakh " ElseIf i = 3 And Val(Left(FIGURE, 2)) > 0 Then Ntow = Ntow & " Thousand " End If FIGURE = Mid(FIGURE, 3) Next i If Val(Left(FIGURE, 1)) > 0 Then Ntow = Ntow & WORDs(Val(Left(FIGURE, 1))) + " Hundred " End If FIGURE = Mid(FIGURE, 2) If Val(Left(FIGURE, 2)) < 20 And Val(Left(FIGURE, 2)) > 0 Then Ntow = Ntow & WORDs(Val(Left(FIGURE, 2))) ElseIf Val(Left(FIGURE, 2)) > 19 Then Ntow = Ntow & tens(Val(Left(FIGURE, 1))) Ntow = Ntow & WORDs(Val(Right(Left(FIGURE, 2), 1))) End If FIGURE = Mid(FIGURE, 4) If Val(FIGURE) > 0 Then Ntow = Ntow & " & " If Val(Left(FIGURE, 2)) > 0 Then Ntow = Ntow & Val(Left(FIGURE, 2)) & "/100" End If End If FIGURE = amt FIGURE = Format(FIGURE, "FIXED")

If Val(FIGURE) > 0 Then

Ntow = Ntow & " Only "

End If

End Function

'================================'

' FUNCTION NTOW '

' MODIFIED BY CYBERT87 '

' A.K.A. GILL BROS @ TECHYV.COM '

' IF YOU HAVE SOME QUESTION '

' FEEL FREE TO MAIL US AT '

' [email protected] '

' OR VISIT OUR WEBSITE '

' http://honeybytes.blogspot.com/ '

'================================'


 

SHARE
Answered By 0 points N/A #155164

Numbers to Words in hundred and Millions

qa-featured

The fact is very simple. Just you have to print the numbers in integer to words. You need the words:

Group 1: one , two, three ………. nine

Group 2: eleven, twelve ………… nineteen

Group 3: twenty, thirty…………… ninety 

 If you are given a 3 digit number, consider one by one digit from the right to left.

Unit place digit is printed using a simple switch case among Group 1.

Tens place digit is printed using a switch statement among group 3. If 1 is found in the tens place then group 2 with units place.

The hundredth place digit has to be printed from group 1 followed by the word “HUNDRED” and so on. You can extend it up to any say, cores, millions etc.

Thanks.

Related Questions