VB 6.0 - converting rupees in words - Asked By Deepak Sanwal on 12-Feb-07 06:56 AM

Dear sir,

is there any function to convert rupees(digit) in words?

like 2000/- to two thousand

Pls help.

Converting numbers to words vb 6.0 - K Pravin Kumar Reddy replied to Deepak Sanwal on 12-Feb-07 07:10 AM

In Vb6.0: http://www.mentalis.org/tips/tip108.shtml
In c++: http://h21007.www2.hp.com/dspp/tech/tech_TechDocumentDetailPage_IDX/1,1701,3556,00.html

Algorithm, in case you want to write your own code.
1. First, break the number down into the highest unit, in this case thousands. So, the first part of our given number produces the number 123, with a unit of thousand.

2. Next, split off the hundreds. So, you have one hundred.

3. The next step is to look at the tens unit. If this number were zero, you would skip it. In this case, it is a two, so the number is twenty. An important exception here is the number one. In this case, you have to apply special English rules (i.e. eleven, twelve, thirteen) and skip the ones digit. So, because the second digit is a two, you now have one hundred twenty.

4. Finally, look at the ones digit. In our case, it is a three, so you have one hundred twenty three.

5. Append the units from step 1: one hundred twenty three thousand.

6. Repeat for the next block. If you are under a thousand, skip the units part. Put both blocks together to produce: one hundred twenty three thousand four hundred fifty six.

reference

http://www.eggheadcafe.com/community/aspnet/8/61186/converting-numbers-to-wor.aspx

converting rupees in words - Ram Chandran replied to Deepak Sanwal on 12-Feb-07 07:11 AM

Dear Sir,

Is there any function to convert rupees(digit) in words?

like 2000/- to two thousand in visualbasic 6.0 Otherwise Please  advice to me.


With Regards

Ram

Spell number as Indian currency - mv ark replied to Ram Chandran on 12-Feb-07 07:29 AM

The function at this link - http://www.freevbcode.com/ShowCode.asp?ID=6475 can be used for Indian currency and it can appropriately spell numbers as lakhs & crores.
convert rupees to words - sundar k replied to Deepak Sanwal on 12-Feb-07 08:47 AM

try this code!

This is a perfect solution of any indian software / application where is requirement  to convert currency Indian Rupees (Rs.) into Words. You can use this program module function RupeesToWord in any application like Excel, Access, VBA, VB6 and VB.NET

http://www.a1vbcode.com/app-3990.asp

just one more,

Convert Currency To Words in Lakh, Crores etc.

http://www.codeproject.com/useritems/CurrencyToWord.asp

you get lot of hits if you google for "Convert rupees to words VB", check it out!

Sushila Patel replied to Deepak Sanwal on 12-Feb-07 01:10 PM

Check the sample "Convert indian Rs. to word"

http://www.freevbcode.com/ShowCode.asp?ID=7814

Sample URL

http://www.freevbcode.com/Source/0306/money.zip

convert rupees to words - aruna sharif replied to sundar k on 01-Mar-07 04:27 AM
end of post
converting rupees in words - aruna sharif replied to Deepak Sanwal on 01-Mar-07 04:31 AM
end of post
Re :: Converting Number into Words - Shailendrasinh Parmar replied to Deepak Sanwal on 10-Nov-08 04:53 AM

See the following article for converting number into words (like 2000 in Two Thausand)

Public Function numtoword(numstr As Variant) As String
' The best data type to feed in is
' Decimal, but it is up to you

Dim tempstr As String
Dim newstr As String
numstr = CDec(numstr)

If numstr = 0 Then
  numtoword = "zero "
  Exit Function
End If

If numstr > 10 ^ 24 Then
  numtoword = "Too big"
  Exit Function
End If

If numstr >= 10 ^ 12 Then
  newstr = numtoword(Int(numstr / 10 ^ 12))
  numstr = ((numstr / 10 ^ 12) - _
  Int(numstr / 10 ^ 12)) * 10 ^ 12
  If numstr = 0 Then
    tempstr = tempstr & newstr & "billion "
  Else
    tempstr = tempstr & newstr & "billion, "
  End If
End If

If numstr >= 10 ^ 6 Then
  newstr = numtoword(Int(numstr / 10 ^ 6))
  numstr = ((numstr / 10 ^ 6) - _
  Int(numstr / 10 ^ 6)) * 10 ^ 6
  If numstr = 0 Then
    tempstr = tempstr & newstr & "million "
  Else
    tempstr = tempstr & newstr & "million, "
  End If
End If

If numstr >= 10 ^ 3 Then
  newstr = numtoword(Int(numstr / 10 ^ 3))
  numstr = ((numstr / 10 ^ 3) - _
  Int(numstr / 10 ^ 3)) * 10 ^ 3
  If numstr = 0 Then
    tempstr = tempstr & newstr & "thousand "
  Else
    tempstr = tempstr & newstr & "thousand, "
  End If
End If

If numstr >= 10 ^ 2 Then
  newstr = numtoword(Int(numstr / 10 ^ 2))
  numstr = ((numstr / 10 ^ 2) - _
  Int(numstr / 10 ^ 2)) * 10 ^ 2
  If numstr = 0 Then
    tempstr = tempstr & newstr & "hundred "
  Else
    tempstr = tempstr & newstr & "hundred and "
  End If
End If

If numstr >= 20 Then
  Select Case Int(numstr / 10)
  Case 2
  tempstr = tempstr & "twenty "
  Case 3
  tempstr = tempstr & "thirty "
  Case 4
  tempstr = tempstr & "forty "
  Case 5
  tempstr = tempstr & "fifty "
  Case 6
  tempstr = tempstr & "sixty "
  Case 7
  tempstr = tempstr & "seventy "
  Case 8
  tempstr = tempstr & "eighty "
  Case 9
  tempstr = tempstr & "ninety "
  End Select
  numstr = ((numstr / 10) - _
  Int(numstr / 10)) * 10
End If

If numstr > 0 Then
  Select Case numstr
  Case 1
  tempstr = tempstr & "one "
  Case 2
  tempstr = tempstr & "two "
  Case 3
  tempstr = tempstr & "three "
  Case 4
  tempstr = tempstr & "four "
  Case 5
  tempstr = tempstr & "five "
  Case 6
  tempstr = tempstr & "six "
  Case 7
  tempstr = tempstr & "seven "
  Case 8
  tempstr = tempstr & "eight "
  Case 9
  tempstr = tempstr & "nine "
  Case 10
  tempstr = tempstr & "ten "
  Case 11
  tempstr = tempstr & "eleven "
  Case 12
  tempstr = tempstr & "twelve "
  Case 13
  tempstr = tempstr & "thirteen "
  Case 14
  tempstr = tempstr & "fourteen "
  Case 15
  tempstr = tempstr & "fifteen "
  Case 16
  tempstr = tempstr & "sixteen "
  Case 17
  tempstr = tempstr & "seventeen "
  Case 18
  tempstr = tempstr & "eighteen "
  Case 19
  tempstr = tempstr & "nineteen "
  End Select
  numstr = ((numstr / 10) - Int(numstr / 10)) * 10
End If
numtoword = tempstr
End Function

Thanks to an anonymous person from Cheats World for this alternative, shorter function:

Dim Number2s(2 To 9) As String
Dim Number1s(1 To 19) As String
Dim Steps(1 To 4) As String

Public Function NumToWord(Numstring As Variant) As String
If Steps(1) = "" Then initstrings
Dim Tempstring As String
Dim Newstring As String
Dim What As Double

If Numstring = 0 Then
  NumToWord = "zero"
  Exit Function
End If

If Numstring > (10 ^ 24) Then _
  NumToWord = "Number is too big"
  Exit Function
End If

Counter = 0
Do
  Counter = Counter + 1
  If Counter > 1 Then
    What = 10 ^ (12 \ ((Counter - 1) * 2))
  Else
    What = 10 ^ 12
  End If

  If Numstring >= What Then
  Newstring = NumToWord(Fix(Numstring / What))
  Numstring = ((Numstring / What) - Fix(Numstring / What)) * What
  If Numstring = 0 Then
    Tempstring = Tempstring & Newstring & Steps(Counter) & " "
  Else
    If Counter = 4 Then
    Tempstring = Tempstring & Newstring & _
    Steps(Counter) & " and ": GoToSkipit
    Tempstring = Tempstring & Newstring & _
    Steps(Counter) & ", "
    Skipit:
  End If
End If

Loop Until Counter = 4

If Numstring >= 20 Then _
Tempstring = Tempstring & _
Number2s(Fix(Numstring / 10)) & " "

If Numstring >= 10 And Numstring < 20 Then _
Tempstring = Tempstring & Number1s(CInt(Numstring)) _
& " ": GoTo Skip2

Numstring = ((Numstring / 10) - Fix(Numstring / 10)) * 10

If Numstring > 0 Then Tempstring = Tempstring & _
Number1s(CInt(Numstring)) & " "
Skip2:

NumToWord = Tempstring

End Function

Public Sub initstrings()
Steps(1) = "billion"
Steps(2) = "million"
Steps(3) = "thousand"
Steps(4) = "hundred"
Number1s(1) = "one"
Number1s(2) = "two"
Number1s(3) = "three"
Number1s(4) = "four"
Number1s(5) = "five"
Number1s(6) = "six"
Number1s(7) = "seven"
Number1s(8) = "eight"
Number1s(9) = "nine"
Number1s(10) = "ten"
Number1s(11) = "eleven"
Number1s(12) = "twelve"
Number1s(13) = "thirteen"
Number1s(14) = "fourteen"
Number1s(15) = "fifteen"
Number1s(16) = "sixteen"
Number1s(17) = "seventeen"
Number1s(18) = "eighteen"
Number1s(19) = "nineteen"
Number2s(2) = "twenty"
Number2s(3) = "thirty"
Number2s(4) = "forty"
Number2s(5) = "fifty"
Number2s(6) = "sixty"
Number2s(7) = "seventy"
Number2s(8) = "eighty"
Number2s(9) = "ninety"

End Sub

Hope it helps.

Rupees to words convertor - nirmal kumar shanmugham replied to Deepak Sanwal on 26-Mar-09 05:25 PM

Hi Deepak,

i have created a macro that converts numbers into words, ranging from 1 to 999999999.99. if you are really interested, i shall help you out.


thnx.

Nirma.


Digit in words - piyush patel replied to Deepak Sanwal on 29-Dec-09 09:00 AM
Option Explicit
' Edited for the use of Indian Users by Kausik Das <Kausik.Das@gmail.com>
'Main Function
Function SpellNumber(ByVal MyNumber)
    Dim Rupees, Paise, Temp
    Dim DecimalPlace, Count
    ReDim Place(9) As String
    Place(2) = " Thousand "
    Place(3) = " Lakh "
    Place(4) = " Crore "
    ' String representation of amount.
    MyNumber = Trim(Str(MyNumber))
    ' Position of decimal place 0 if none.
    DecimalPlace = InStr(MyNumber, ".")
    ' Convert Paise and set MyNumber to dollar amount.
    If DecimalPlace > 0 Then
        Paise = GetTens(Left(Mid(MyNumber, DecimalPlace + 1) & _
                  "00", 2))
        MyNumber = Trim(Left(MyNumber, DecimalPlace - 1))
    End If
    Count = 1
    Do While MyNumber <> ""
        If Count <> 1 Then
            Temp = GetHundreds(Right(MyNumber, 2))
            If Temp <> "" Then Rupees = Temp & Place(Count) & Rupees
            If Len(MyNumber) > 2 Then
                MyNumber = Left(MyNumber, Len(MyNumber) - 2)
            Else
                MyNumber = ""
            End If
        Else
            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
        End If
        Count = Count + 1
    Loop
    Select Case Rupees
        Case ""
            Rupees = " "
        Case "One"
            Rupees = "Re One "
         Case Else
            Rupees = "Rupees " & Rupees
    End Select
    Select Case Paise
        Case ""
            Paise = " Zero Paise "
        Case "One"
            Paise = " and Paise One"
        Case Else
            Paise = "Paise " & Paise
    End Select
    If Rupees <> " " Then Paise = " and " & Paise
    SpellNumber = " [ " & Rupees & Paise & " Only ] "
End Function
' Edited for the use of Indian Users by Kausik Das <Kausik.Das@gmail.com>
' 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
' Edited for the use of Indian Users by Kausik Das <Kausik.Das@gmail.com>
' 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
' Edited for the use of Indian Users by Kausik Das <Kausik.Das@gmail.com>
' 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

==================
How to Use the SpellNumber Sample Function

SpellNumber(32.50) 
saurabh replied to piyush patel on 29-Mar-10 09:48 PM
best ever code i ve found till date for digit conversion in rs.
hats off to you
thanks a lot

saurabh jain
hrushi replied to saurabh on 08-Jun-10 06:42 AM

dear saurabh,

i have pasted the code into excel but it doesnt work....pl. guide me....

thank u,
regards