Results 1 to 12 of 12
  1. #1
    Join Date
    Mar 2006
    Posts
    33
    Provided Answers: 1

    Question Answered: Help need to convert the amount into words

    hey all
    any one any ideas what function i need to write to convert a value to its text literal......example:

    1234221 should become twelve lac thirty four thousand and two hundred and twenty one

    all help welcome here believe me its straight 15 hrs now either im dumb or ...........!

  2. Best Answer
    Posted by abhichoudhary

    "convert a number to text ie 123456 to one lakh twenty three thousand four hundred and fiffty six

    ok guys im a hobby programmer and i did it....with lots of help to start out.....
    i improved it i hope.... adding "and" in the rt places was pretty tricky......i mean when is it twenty thousand five hundred..... vs twenty thousand and five hundred only kinda thing.

    the code is in the att doc file

    also it is in crore lakh and thousand format
    i removed the decimal handling i did not need it
    if any one improves or finds a bug please please do post back the rt version
    thanks!

    i am glad and wish all of you lots of happiness!"


  3. #2
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    what like cheque printing you mean?

    I don't think there is an off the shelf solution, you will probably need to write a function
    I'd rather be riding on the Tiger 800 or the Norton

  4. #3
    Join Date
    Dec 2002
    Location
    Préverenges, Switzerland
    Posts
    3,740
    have a look at this

    izy
    currently using SS 2008R2

  5. #4
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    I tend to forget how truly usefull that site is......

    perhaps we need toget it as part of teddy's FAQ....
    I'd rather be riding on the Tiger 800 or the Norton

  6. #5
    Join Date
    Mar 2006
    Posts
    33
    Provided Answers: 1

    thanks but.....

    here is the code from msdn i found.... i need to modify it for lakhs and crores
    like

    44,55,67,864


    is fourty four crore fifty five lakh sixty seven thousand and eight hundred and sixty four rupees only


    no reqmt of the after decimals

    the code is as under pl modify it guys im stuck not been into this since a year now and im out of time..
    thanks so much.




    Function ConvertCurrencyToEnglish(ByVal MyNumber)
    Dim Temp
    Dim Dollars, Cents
    Dim DecimalPlace, Count

    ReDim Place(9) As String
    Place(2) = " Thousand "
    Place(3) = " Million "
    Place(4) = " Billion "
    Place(5) = " Trillion "

    ' Convert MyNumber to a string, trimming extra spaces.
    MyNumber = Trim(Str(MyNumber))

    ' Find decimal place.
    DecimalPlace = InStr(MyNumber, ".")

    ' If we find decimal place...
    If DecimalPlace > 0 Then
    ' Convert cents
    Temp = Left(Mid(MyNumber, DecimalPlace + 1) & "00", 2)
    Cents = ConvertTens(Temp)

    ' Strip off cents from remainder to convert.
    MyNumber = Trim(Left(MyNumber, DecimalPlace - 1))
    End If

    Count = 1
    Do While MyNumber <> ""
    ' Convert last 3 digits of MyNumber to English dollars.
    Temp = ConvertHundreds(Right(MyNumber, 3))
    If Temp <> "" Then Dollars = Temp & Place(Count) & Dollars
    If Len(MyNumber) > 3 Then
    ' Remove last 3 converted digits from MyNumber.
    MyNumber = Left(MyNumber, Len(MyNumber) - 3)
    Else
    MyNumber = ""
    End If
    Count = Count + 1
    Loop

    ' Clean up dollars.
    Select Case Dollars
    Case ""
    Dollars = "No Dollars"
    Case "One"
    Dollars = "One Dollar"
    Case Else
    Dollars = Dollars & " Dollars"
    End Select

    ' Clean up cents.
    Select Case Cents
    Case ""
    Cents = " And No Cents"
    Case "One"
    Cents = " And One Cent"
    Case Else
    Cents = " And " & Cents & " Cents"
    End Select

    ConvertCurrencyToEnglish = Dollars & Cents
    End Function


    Private Function ConvertDigit(ByVal MyDigit)
    Select Case Val(MyDigit)
    Case 1: ConvertDigit = "One"
    Case 2: ConvertDigit = "Two"
    Case 3: ConvertDigit = "Three"
    Case 4: ConvertDigit = "Four"
    Case 5: ConvertDigit = "Five"
    Case 6: ConvertDigit = "Six"
    Case 7: ConvertDigit = "Seven"
    Case 8: ConvertDigit = "Eight"
    Case 9: ConvertDigit = "Nine"
    Case Else: ConvertDigit = ""
    End Select

    End Function

    Private Function ConvertHundreds(ByVal MyNumber)
    Dim Result As String

    ' Exit if there is nothing to convert.
    If Val(MyNumber) = 0 Then Exit Function

    ' Append leading zeros to number.
    MyNumber = Right("000" & MyNumber, 3)

    ' Do we have a hundreds place digit to convert?
    If Left(MyNumber, 1) <> "0" Then
    Result = ConvertDigit(Left(MyNumber, 1)) & " Hundred "
    End If

    ' Do we have a tens place digit to convert?
    If Mid(MyNumber, 2, 1) <> "0" Then
    Result = Result & ConvertTens(Mid(MyNumber, 2))
    Else
    ' If not, then convert the ones place digit.
    Result = Result & ConvertDigit(Mid(MyNumber, 3))
    End If

    ConvertHundreds = Trim(Result)
    End Function


    Private Function ConvertTens(ByVal MyTens)
    Dim Result As String

    ' Is value between 10 and 19?
    If Val(Left(MyTens, 1)) = 1 Then
    Select Case Val(MyTens)
    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
    ' .. otherwise it's between 20 and 99.
    Select Case Val(Left(MyTens, 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

    ' Convert ones place digit.
    Result = Result & ConvertDigit(Right(MyTens, 1))
    End If

    ConvertTens = Result
    End Function

  7. #6
    Join Date
    Dec 2002
    Location
    Préverenges, Switzerland
    Posts
    3,740
    you didn't like the mvps link?

    the way thous, mills, bills are constructed is much more obvious in the Joe Foster version.

    tough luck for you that
    lakh*lakh <> crore
    either you redefine the way the sub-continent counts, or you re/define the constants.

    izy
    currently using SS 2008R2

  8. #7
    Join Date
    Mar 2006
    Posts
    33
    Provided Answers: 1
    yup izy
    one cant fight the system
    we need to implement the protocols...
    i am just going through the mvps site, ill see if i can understand it soon....
    let me look at it.....nights young....
    hey im foxed i use the lookups so much and here i find i shouldnt use them......then how do i create the comboboxes and make the user select the relevant options.....?
    abhi

  9. #8
    Join Date
    Dec 2002
    Location
    Préverenges, Switzerland
    Posts
    3,740
    unbound combo feeding the lookuptable ID to the (if you REALLY MUST use them) bound field.

    izy
    currently using SS 2008R2

  10. #9
    Join Date
    Mar 2006
    Posts
    33
    Provided Answers: 1

    Smile

    convert a number to text ie 123456 to one lakh twenty three thousand four hundred and fiffty six

    ok guys im a hobby programmer and i did it....with lots of help to start out.....
    i improved it i hope.... adding "and" in the rt places was pretty tricky......i mean when is it twenty thousand five hundred..... vs twenty thousand and five hundred only kinda thing.

    the code is in the att doc file

    also it is in crore lakh and thousand format
    i removed the decimal handling i did not need it
    if any one improves or finds a bug please please do post back the rt version
    thanks!

    i am glad and wish all of you lots of happiness!
    Attached Files Attached Files

  11. #10
    Join Date
    Dec 2004
    Location
    Madison, WI
    Posts
    3,926

    Convert number to text for checks

    Here's another example. It can handle 10 digits (before the decimal) and it's based on a table to convert the numbers to currency for checks. It will also do the cents so something like $1,234.34 will translate to One Thousand Two Hundred Thirty Four and 34/100. (look at the Convert Check Amount to Text module and the dbo_LookupCurrency table - ignore all the other stuff.)
    Attached Files Attached Files
    Last edited by pkstormy; 03-29-06 at 10:49.
    Expert Database Programming
    MSAccess since 1.0, SQL Server since 6.5, Visual Basic (5.0, 6.0)

  12. #11
    Join Date
    Dec 2002
    Location
    Préverenges, Switzerland
    Posts
    3,740
    i see you are parsing strings.
    is it worth comparing execution speed with "parsing" numbers?

    given an arbitrary number in curIn

    Const cstCrore = 10000000 ' i think i have one too many 0 here
    Const cstLakh = 100000 ' i think i have one too many 0 here as well
    Const cstThous = 1000
    Const cstHund = 100
    Const cstTeen = 10
    Dim curCrore As Currency
    Dim curLakh As Currency
    Dim curThous As Currency
    Dim curHund As Currency
    Dim curTeen As Currency
    Dim curUnits As Currency
    Dim curBuff As Currency
    curBuff = curIn
    curCrore = curBuff \ cstCrore
    curBuff = curBuff - curCrore * cstCrore
    curLakh = curBuff \ cstLakh
    curBuff = curBuff - curLakh * cstLakh
    curThous = curBuff \ cstThous
    curBuff = curBuff - curThous * cstThous
    curHund = curBuff \ cstHund
    curBuff = curBuff - curHund * cstHund
    curTeen = curBuff \ cstTeen
    curBuff = curBuff - curTeen * cstTeen
    curUnits = curBuff

    NB \ <> / !!

    izy
    currently using SS 2008R2

  13. #12
    Join Date
    Dec 2004
    Location
    Madison, WI
    Posts
    3,926

    Currency code

    I really like abhichoudhary's code!! (a lot better than mine - which is very sloppy and not fully tested.) I haven't been able to make it not work right. Thanks abhichoudhary!
    Expert Database Programming
    MSAccess since 1.0, SQL Server since 6.5, Visual Basic (5.0, 6.0)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •