0% found this document useful (1 vote)
126 views4 pages

Spellnumber Bracket

The document describes a VBScript function called RatanNumber that takes a numeric value as input and returns an English text representation of that number. It breaks the number down into individual places (crores, lakhs, thousands, hundreds, tens, ones), converts each place value to text using additional functions, and combines them with separators into a final string output. It can optionally include or exclude the word "Rupees" depending on a passed parameter.

Uploaded by

ratanlourembam
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (1 vote)
126 views4 pages

Spellnumber Bracket

The document describes a VBScript function called RatanNumber that takes a numeric value as input and returns an English text representation of that number. It breaks the number down into individual places (crores, lakhs, thousands, hundreds, tens, ones), converts each place value to text using additional functions, and combines them with separators into a final string output. It can optionally include or exclude the word "Rupees" depending on a passed parameter.

Uploaded by

ratanlourembam
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Function RatanNumber(ByVal MyNumber, Optional incRupees As Boolean = True) Dim Crores, Lakhs, Rupees, Paise, Temp Dim DecimalPlace

As Long, Count As Long Dim myLakhs, myCrores ReDim Place(9) As String Place(2) = " thousand ": Place(3) = " Million " Place(4) = " Billion ": Place(5) = " Trillion " ' String representation of amount. MyNumber = Trim(Str(MyNumber)) ' Position of decimal place 0 if none. DecimalPlace = InStr(MyNumber, ".") ' Convert Paise and set MyNumber to Rupees amount. If DecimalPlace > 0 Then Paise = GetTens(Left(Mid(MyNumber, DecimalPlace + 1) & "00", 2)) MyNumber = Trim(Left(MyNumber, DecimalPlace - 1)) End If myCrores = MyNumber \ 10000000 myLakhs = (MyNumber - myCrores * 10000000) \ 100000 MyNumber = MyNumber - myCrores * 10000000 - myLakhs * 100000 Count = 1 Do While myCrores <> "" Temp = GetHundreds(Right(myCrores, 3)) If Temp <> "" Then Crores = Temp & Place(Count) & Crores If Len(myCrores) > 3 Then myCrores = Left(myCrores, Len(myCrores) - 3) Else myCrores = "" End If Count = Count + 1 Loop Count = 1 Do While myLakhs <> "" Temp = GetHundreds(Right(myLakhs, 3)) If Temp <> "" Then Lakhs = Temp & Place(Count) & Lakhs If Len(myLakhs) > 3 Then myLakhs = Left(myLakhs, Len(myLakhs) - 3) Else myLakhs = "" End If Count = Count + 1 Loop Count = 1 Do While MyNumber <> "" Temp = GetHundreds(Right(MyNumber, 3)) If Temp <> "" Then Rupees = Temp & Place(Count) & Rupees

If Len(MyNumber) > 3 Then MyNumber = Left(MyNumber, Len(MyNumber) - 3) Else MyNumber = "" End If Count = Count + 1 Loop Select Case crores Case "": crores = "" Case "one": crores = " one crore " Case Else: crores = crores & " crores " End Select Select Case lakhs Case "": lakhs = "" Case "one": lakhs = " one lakh " Case Else: lakhs = lakhs & " lakhs " End Select Select Case Rupees Case "": Rupees = " " Case "One": Rupees = "one " Case Else:

Rupees = Rupees End Select Select Case Paise Case "": Paise = ") only " Case "One": Paise = " and paise one )only " Case Else: Paise = " and paise " & Paise & ") only " End Select RatanNumber = IIf(incRupees, "(Rupees ", "") & Crores & _ Lakhs & Rupees & Paise End Function ' Converts a number from 100-999 into text 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 Result = GetDigit(Mid(MyNumber, 1, 1)) & " hundred " End If ' Convert the tens and ones place. If Mid(MyNumber, 2, 1) <> "0" Then Result = Result & GetTens(Mid(MyNumber, 2))

Else Result = Result & GetDigit(Mid(MyNumber, 3)) End If GetHundreds = Result End Function ' Converts a number from 10 to 99 into text. 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 = "ten" Case 11: Result = "eleven" Case 12: Result = "twelve" Case 13: Result = "thirteen" Case 14: Result = "fourteen" Case 15: Result = "fifteen" Case 16: Result = "sixteen" Case 17: Result = "seventeen" Case 18: Result = "eighteen" Case 19: Result = "nineteen" Case Else End Select Else ' If value between 20-99... Select Case Val(Left(TensText, 1)) Case 2: Result = "twenty " Case 3: Result = "thirty " Case 4: Result = "forty " Case 5: Result = "fifty " Case 6: Result = "sixty " Case 7: Result = "seventy " Case 8: Result = "eighty " Case 9: Result = "ninety " 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. Function GetDigit(Digit) Select Case Val(Digit) Case 1: GetDigit = "one" Case 2: GetDigit = "two"

Case 3: GetDigit = "three" Case 4: GetDigit = "four" Case 5: GetDigit = "five" Case 6: GetDigit = "six" Case 7: GetDigit = "seven" Case 8: GetDigit = "eight" Case 9: GetDigit = "nine" Case Else: GetDigit = "" End Select End Function

You might also like