Convert number to words Indian system (1 Viewer)

bijondhanbad

Registered User.
Local time
Today, 23:03
Joined
Sep 8, 2006
Messages
33
Will someone help me with a function or VBA code for converting numbers to words in the Indian system for use in MS Access.

Like 1,23,50,432 as one crore twenty three lacs fifty thousand four hundred thirty two.
 

raskew

AWF VIP
Local time
Today, 12:33
Joined
Jun 2, 2001
Messages
2,734
Hi -

From a US point-of-view:

After looking up 'Crore' on Google and Ask.com -- have to say 'What a Great Problem'! I'd have to ask for money in advance on this one. Seems this is going to be a monster. Really look forward to seeing if someone has the time to resolve it.

Best Wishes and Good Luck -- Bob
 

raskew

AWF VIP
Local time
Today, 12:33
Joined
Jun 2, 2001
Messages
2,734
RV -

There's something wrong here.

Have you followed these thru? First site says:
It means that digits are grouped in groups of two digits each i.e. thousands, millions, billions etc. However, people in India are habitual for groups of three, two, two..
exactly the reverse, i.e. people in the US/European community group digits in groups of three, not two. Please provide a working example.

Best wishes, Bob

P.S. Site #2 is dead.
 
Last edited:

raskew

AWF VIP
Local time
Today, 12:33
Joined
Jun 2, 2001
Messages
2,734
RV -

Are you conscious?

And the answer is.....?


Bob
 

RuralGuy

AWF VIP
Local time
Today, 11:33
Joined
Jul 2, 2005
Messages
13,826
Bob,
Here's what RV's second link pointed to:
Code:
Hello Everybody,
Firstly I thank all of whom have helped in finding a code for converting numbers to string.
I here am giving a totally different code which works perfectly till 9 Crores

The Code is ---
Option Compare Database
Public Function Spell(InVal) As String

Dim Ones(100) As Variant
Dim X(10) As Variant
Dim Real, Imax, Idigit(30), J, I1
Dim Value As String

X(1) = ""
X(2) = ""
X(3) = " Hundred "
X(4) = " Thousand "
X(5) = ""
X(6) = " Lakh "
X(7) = ""
X(8) = " Crore "
X(9) = ""

Ones(1) = " One "
Ones(2) = " Two "
Ones(3) = " Three "
Ones(4) = " Four "
Ones(5) = " Five "
Ones(6) = " Six "
Ones(7) = " Seven "
Ones(8) = " Eight "
Ones(9) = " Nine "
Ones(10) = " Ten "
Ones(11) = " Eleven "
Ones(12) = " Twelve "
Ones(13) = " Thirteen "
Ones(14) = " Fourteen "
Ones(15) = " Fifteen "
Ones(16) = " Sixteen "
Ones(17) = " Seventeen "
Ones(18) = " Eighteen "
Ones(19) = " Nineteen "
Ones(20) = " Twenty "
Ones(30) = " Thirty "
Ones(40) = " Fourty "
Ones(50) = " Fifty "
Ones(60) = " Sixty "
Ones(70) = " Seventy "
Ones(80) = " Eighty "
Ones(90) = " Ninety "
Ones(100) = " Hundred "

Real = Int(InVal)
Imax = Len(Real)

Value = ""
For i = 1 To Imax
    Idigit(i) = Real - 10 * Int(Real / 10)
    Real = Int(Real / 10)
Next i

For i = 1 To Imax
    I1 = Imax - i + 1
    J = Idigit(I1)
    If I1 <> 9 Then GoTo 60
    If J <> 1 Then GoTo 65
    J = 10 + Idigit(I1 - 1)
    i = i + 1
    I1 = I1 - 1
    GoTo 99
65:
    J = 10 * J
    If Idigit(I1) = 0 And Idigit(I1 - 1) = 0 Then
        i = i + 1
        GoTo 100
    End If
60:
    If I1 <> 7 Then GoTo 80
    If J <> 1 Then GoTo 85
    J = 10 + Idigit(I1 - 1)
    i = i + 1
    I1 = I1 - 1
    GoTo 99
85:
    J = 10 * J
    If Idigit(I1) = 0 And Idigit(I1 - 1) = 0 Then
        i = i + 1
        GoTo 100
    End If
80:
    If I1 <> 5 Then GoTo 90
    If J <> 1 Then GoTo 75
    J = 10 + Idigit(I1 - 1)
    i = i + 1
    I1 = I1 - 1
    GoTo 99
75:
    J = 10 * J
    If Idigit(I1) = 0 And Idigit(I1 - 1) = 0 Then
        i = i + 1
        GoTo 100
    End If
90:
    If I1 <> 3 Then GoTo 95
    If Idigit(I1) = 0 Then GoTo 100
95:
    If I1 <> 2 Then GoTo 99
    If J <> 1 Then GoTo 98
    J = 10 + Idigit(I1 - 1)
    i = i + 1
    I1 = I1 - 1
    GoTo 99
98:
    J = 10 * J
99:
    Value = Value + Ones(J) + X(I1)
100:
Next i
Spell = Value
End Function
---
If any bugs r present plz let me know.
Thankz
I don't know why the direct link doesn't work.
 

bijondhanbad

Registered User.
Local time
Today, 23:03
Joined
Sep 8, 2006
Messages
33
RuralGuy said:
Bob,
Here's what RV's second link pointed to:
Code:
Hello Everybody,
Firstly I thank all of whom have helped in finding a code for converting numbers to string.
I here am giving a totally different code which works perfectly till 9 Crores

The Code is ---
Option Compare Database
Public Function Spell(InVal) As String

Dim Ones(100) As Variant
Dim X(10) As Variant
Dim Real, Imax, Idigit(30), J, I1
Dim Value As String

X(1) = ""
X(2) = ""
X(3) = " Hundred "
X(4) = " Thousand "
X(5) = ""
X(6) = " Lakh "
X(7) = ""
X(8) = " Crore "
X(9) = ""

Ones(1) = " One "
Ones(2) = " Two "
Ones(3) = " Three "
Ones(4) = " Four "
Ones(5) = " Five "
Ones(6) = " Six "
Ones(7) = " Seven "
Ones(8) = " Eight "
Ones(9) = " Nine "
Ones(10) = " Ten "
Ones(11) = " Eleven "
Ones(12) = " Twelve "
Ones(13) = " Thirteen "
Ones(14) = " Fourteen "
Ones(15) = " Fifteen "
Ones(16) = " Sixteen "
Ones(17) = " Seventeen "
Ones(18) = " Eighteen "
Ones(19) = " Nineteen "
Ones(20) = " Twenty "
Ones(30) = " Thirty "
Ones(40) = " Fourty "
Ones(50) = " Fifty "
Ones(60) = " Sixty "
Ones(70) = " Seventy "
Ones(80) = " Eighty "
Ones(90) = " Ninety "
Ones(100) = " Hundred "

Real = Int(InVal)
Imax = Len(Real)

Value = ""
For i = 1 To Imax
    Idigit(i) = Real - 10 * Int(Real / 10)
    Real = Int(Real / 10)
Next i

For i = 1 To Imax
    I1 = Imax - i + 1
    J = Idigit(I1)
    If I1 <> 9 Then GoTo 60
    If J <> 1 Then GoTo 65
    J = 10 + Idigit(I1 - 1)
    i = i + 1
    I1 = I1 - 1
    GoTo 99
65:
    J = 10 * J
    If Idigit(I1) = 0 And Idigit(I1 - 1) = 0 Then
        i = i + 1
        GoTo 100
    End If
60:
    If I1 <> 7 Then GoTo 80
    If J <> 1 Then GoTo 85
    J = 10 + Idigit(I1 - 1)
    i = i + 1
    I1 = I1 - 1
    GoTo 99
85:
    J = 10 * J
    If Idigit(I1) = 0 And Idigit(I1 - 1) = 0 Then
        i = i + 1
        GoTo 100
    End If
80:
    If I1 <> 5 Then GoTo 90
    If J <> 1 Then GoTo 75
    J = 10 + Idigit(I1 - 1)
    i = i + 1
    I1 = I1 - 1
    GoTo 99
75:
    J = 10 * J
    If Idigit(I1) = 0 And Idigit(I1 - 1) = 0 Then
        i = i + 1
        GoTo 100
    End If
90:
    If I1 <> 3 Then GoTo 95
    If Idigit(I1) = 0 Then GoTo 100
95:
    If I1 <> 2 Then GoTo 99
    If J <> 1 Then GoTo 98
    J = 10 + Idigit(I1 - 1)
    i = i + 1
    I1 = I1 - 1
    GoTo 99
98:
    J = 10 * J
99:
    Value = Value + Ones(J) + X(I1)
100:
Next i
Spell = Value
End Function
---
If any bugs r present plz let me know.
Thankz
I don't know why the direct link doesn't work.
thanks it worked.
 

RuralGuy

AWF VIP
Local time
Today, 11:33
Joined
Jul 2, 2005
Messages
13,826
Glad to hear you got it working. Thanks for posting back with your success.
 

RV

Registered User.
Local time
Today, 18:33
Joined
Feb 8, 2002
Messages
1,115
raskew said:
RV -

Are you conscious?

And the answer is.....?


Bob

Well, that next time you need to put on you glasses first before jumping to conclusions :D

Rv
 

w8ingforyou

Registered User.
Local time
Today, 10:33
Joined
Jan 19, 2017
Messages
11
This Post in Particular is a reason i would Continue to Dev. My Ms access DB VBA

Made My Day!

Regards
Thanks again
Saketh Sharath
 
Local time
Today, 22:33
Joined
Aug 19, 2021
Messages
212
Bob,
Here's what RV's second link pointed to:
Code:
Hello Everybody,
Firstly I thank all of whom have helped in finding a code for converting numbers to string.
I here am giving a totally different code which works perfectly till 9 Crores

The Code is ---
Option Compare Database
Public Function Spell(InVal) As String

Dim Ones(100) As Variant
Dim X(10) As Variant
Dim Real, Imax, Idigit(30), J, I1
Dim Value As String

X(1) = ""
X(2) = ""
X(3) = " Hundred "
X(4) = " Thousand "
X(5) = ""
X(6) = " Lakh "
X(7) = ""
X(8) = " Crore "
X(9) = ""

Ones(1) = " One "
Ones(2) = " Two "
Ones(3) = " Three "
Ones(4) = " Four "
Ones(5) = " Five "
Ones(6) = " Six "
Ones(7) = " Seven "
Ones(8) = " Eight "
Ones(9) = " Nine "
Ones(10) = " Ten "
Ones(11) = " Eleven "
Ones(12) = " Twelve "
Ones(13) = " Thirteen "
Ones(14) = " Fourteen "
Ones(15) = " Fifteen "
Ones(16) = " Sixteen "
Ones(17) = " Seventeen "
Ones(18) = " Eighteen "
Ones(19) = " Nineteen "
Ones(20) = " Twenty "
Ones(30) = " Thirty "
Ones(40) = " Fourty "
Ones(50) = " Fifty "
Ones(60) = " Sixty "
Ones(70) = " Seventy "
Ones(80) = " Eighty "
Ones(90) = " Ninety "
Ones(100) = " Hundred "

Real = Int(InVal)
Imax = Len(Real)

Value = ""
For i = 1 To Imax
    Idigit(i) = Real - 10 * Int(Real / 10)
    Real = Int(Real / 10)
Next i

For i = 1 To Imax
    I1 = Imax - i + 1
    J = Idigit(I1)
    If I1 <> 9 Then GoTo 60
    If J <> 1 Then GoTo 65
    J = 10 + Idigit(I1 - 1)
    i = i + 1
    I1 = I1 - 1
    GoTo 99
65:
    J = 10 * J
    If Idigit(I1) = 0 And Idigit(I1 - 1) = 0 Then
        i = i + 1
        GoTo 100
    End If
60:
    If I1 <> 7 Then GoTo 80
    If J <> 1 Then GoTo 85
    J = 10 + Idigit(I1 - 1)
    i = i + 1
    I1 = I1 - 1
    GoTo 99
85:
    J = 10 * J
    If Idigit(I1) = 0 And Idigit(I1 - 1) = 0 Then
        i = i + 1
        GoTo 100
    End If
80:
    If I1 <> 5 Then GoTo 90
    If J <> 1 Then GoTo 75
    J = 10 + Idigit(I1 - 1)
    i = i + 1
    I1 = I1 - 1
    GoTo 99
75:
    J = 10 * J
    If Idigit(I1) = 0 And Idigit(I1 - 1) = 0 Then
        i = i + 1
        GoTo 100
    End If
90:
    If I1 <> 3 Then GoTo 95
    If Idigit(I1) = 0 Then GoTo 100
95:
    If I1 <> 2 Then GoTo 99
    If J <> 1 Then GoTo 98
    J = 10 + Idigit(I1 - 1)
    i = i + 1
    I1 = I1 - 1
    GoTo 99
98:
    J = 10 * J
99:
    Value = Value + Ones(J) + X(I1)
100:
Next i
Spell = Value
End Function
---
If any bugs r present plz let me know.
Thankz
I don't know why the direct link doesn't work.
Hi I want One Hundred Thousand instead of Lakh.
I want to use
Place(2) = "Thousand "
Place(3) = "Million "
Place(4) = "Billion "
Place(5) = "Trillion "

But not Rupees instead of Doler and Paisas instead of Cents.
I have this VB code but its working on excel but I want to use this code in my Ms Access Database.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 01:33
Joined
May 7, 2009
Messages
19,246
Code:
'arnelgp
Public Function SpellDoler(ByVal num As Double, Optional ByVal properCase As Boolean = False) As String
Dim i As Integer, sFrac As String
Dim sNum As String
sNum = CStr(num)
i = InStrRev(sNum, ".")
If i <> 0 Then
    sFrac = Mid$(sNum, i)
    'remove the fraction part
    sNum = Replace$(sNum, sFrac, "")
    sFrac = Right$(sFrac, Len(sFrac) - 1)
    If Len(sFrac) > 2 Then
        sFrac = Left$(sFrac, 2)
    End If
End If
If Len(sFrac) <> 0 Then
    sNum = NumberToString(Val(sNum)) & " doler and " & NumberToString(sFrac) & " praisas"
Else
    sNum = NumberToString(Val(sNum)) & " doler"
End If
'remove the ","
sNum = Replace$(sNum, ",", "")
If properCase Then
    sNum = StrConv(sNum, vbProperCase)
End If
SpellDoler = sNum
End Function

'http://vb-helper.com/howto_number_to_words3.html

' Return a word representation of the whole number value.
Public Function NumberToString(ByVal num_str As String, _
    Optional ByVal use_us_group_names As Boolean = True) As _
    String
Const CURRENCY_CHAR As String = "$"
Const SEPARATOR As String = ","
Const DECIMAL_POINT As String = "."

Dim groups() As String
Dim pos As Integer
Dim num_groups As Integer
Dim result As String
Dim group_num As Integer
Dim group_str As String
Dim group_value As Integer

    ' Get the appropiate group names.
    If use_us_group_names Then
        groups = Split(",thousand,million,billion," & _
            "trillion,quadrillion,quintillion," & _
            "sextillion,septillion,octillion," & _
            "nonillion,decillion,undecillion," & _
            "duodecillion,tredecillion," & _
            "quattuordecillion,quindecillion," & _
            "sexdecillion,septendecillion," & _
            "octodecillion,novemdecillion," & _
            "vigintillion", ",")
    Else
        groups = Split(",thousand,million," & _
            "milliard,billion,1000 billion," & _
            "trillion,1000 trillion,quadrillion," & _
            "1000 quadrillion,quintillion," & _
            "1000 quintillion,sextillion," & _
            "1000 sextillion,septillion," & _
            "1000 septillion,octillion," & _
            "1000 octillion,nonillion," & _
            "1000 nonillion,decillion," & _
            "1000 decillion", ",")
    End If

    ' Clean the string a bit.
    ' Remove "$", ",", leading zeros, and
    ' anything after a decimal point.
    num_str = Replace$(num_str, CURRENCY_CHAR, "")
    num_str = Replace$(num_str, SEPARATOR, "")
    Do While Left$(num_str, 1) = "0"
        num_str = Mid$(num_str, 2)
    Loop
    pos = InStr(num_str, DECIMAL_POINT)
    If pos = 1 Then
        NumberToString = "zero"
        Exit Function
    ElseIf pos > 1 Then
        num_str = Left$(num_str, pos - 1)
    End If

    ' See how many groups there will be.
    num_groups = (Len(num_str) + 2) \ 3

    ' Pad so length is a multiple of 3.
    num_str = Space$(num_groups * 3 - Len(num_str)) & _
        num_str

    ' Process the groups, largest first.
    result = ""
    For group_num = num_groups - 1 To 0 Step -1
        ' Get the next three digits.
        group_str = Mid$(num_str, 1, 3)
        num_str = Mid$(num_str, 4)
        group_value = CInt(group_str)

        ' Convert the group into words.
        If group_value > 0 Then
            If group_num >= UBound(groups) Then
                result = result & GroupToWords(group_value) _
                    & _
                    " ?, "
            Else
                result = result & GroupToWords(group_value) _
                    & _
                    " " & groups(group_num) & ", "
            End If
        End If
    Next group_num

    ' Remove the trailing ", ".
    If Right$(result, 2) = ", " Then
        result = Left$(result, Len(result) - 2)
    ElseIf Len(result) = 0 Then
        result = "zero"
    End If

    NumberToString = Trim$(result)
End Function

' Convert a number between 0 and 999 into words.
Private Function GroupToWords(ByVal num As Integer) As _
    String
Static done_before As Boolean
Static one_to_nineteen() As String
Static multiples_of_ten() As String

Dim digit As Integer
Dim result As String

    If Not done_before Then
        done_before = True
        one_to_nineteen = Split("zero,one,two,three," & _
            "four,five,six,seven,eight,nine,ten," & _
            "eleven,twelve,thirteen,fourteen,fifteen," & _
            "sixteen,seventeen,eightteen,nineteen", ",")
        multiples_of_ten = Split("twenty,thirty," & _
            "forty,fifty,sixty,seventy,eighty,ninety", ",")
    End If

    ' If the number is 0, return an empty string.
    GroupToWords = 0
    If num = 0 Then Exit Function

    ' Handle the hundreds digit.
    result = ""
    If num > 99 Then
        digit = num \ 100
        num = num Mod 100
        result = one_to_nineteen(digit) & " hundred"
    End If

    ' If num = 0, we have hundreds only.
    If num = 0 Then
        GroupToWords = Trim$(result)
        Exit Function
    End If

    ' See if the rest is less than 20.
    If num < 20 Then
        ' Look up the correct name.
        result = result & " " & one_to_nineteen(num)
    Else
        ' Handle the tens digit.
        digit = num \ 10
        num = num Mod 10
        result = result & " " & multiples_of_ten(digit - 2)

        ' Handle the final digit.
        If num > 0 Then
            result = result & " " & one_to_nineteen(num)
        End If
    End If

    GroupToWords = Trim$(result)
End Function
?spelldoler(16546816564.03,True)
Sixteen Billion Five Hundred Forty Six Million Eight Hundred Sixteen Thousand Five Hundred Sixty Four Doler And Three Praisas
 

Users who are viewing this thread

Top Bottom