Solved

Converting numbers to words (For Cheques)

Posted on 2008-10-27
14
1,070 Views
Last Modified: 2013-11-23
I'm doing a cheque writer software. Everything so far is good. However, I need a function that converts numbers to english words. For example, 10,011 should be converted to ten thousand and eleven dollars...etc etc

I know there's an example on http://delphi.about.com/od/objectpascalide/a/curr2words.htm that illustrates what I want, but that example has some mistakes when placing commas and ands. I want a function that correctly converts numbers to english words including correct comma places and "and" places.

I'm using Delphi 2009.
0
Comment
Question by:Whisper700
  • 6
  • 4
  • 2
  • +1
14 Comments
 
LVL 36

Expert Comment

by:Geert Gruwez
Comment Utility
this component should do the trick

http://www.scalabium.com/smoneystr.htm
0
 

Author Comment

by:Whisper700
Comment Utility
Geert,

I appreciate your help, but the file you gave megot me lost. It has more than 200 files in it and i didnt really know how to use it at all
0
 

Author Comment

by:Whisper700
Comment Utility
Geert,

I worked it out and im able to use that file now. But the problem is that it does not produce strings that are suitable for checks. For example, 10,000,003 was translated to TEN MILLION THREE. For cheques, a valid amount would be TEN MILLION AND THREE. The component you gave me does not include AND in the string of words.
0
 
LVL 36

Accepted Solution

by:
Geert Gruwez earned 210 total points
Comment Utility
this one does, but ... not free

http://www.mygoldensoft.com/features/num2text.htm
0
 
LVL 1

Expert Comment

by:Eamon
Comment Utility
Private Sub ConvertAmount(ByVal Amt As Integer)
        Millions = "ZERO"
        HundredThousands = "ZERO"
        TenThousands = "ZERO"
        Thousands = "ZERO"
        Hundreds = "ZERO"
        Tens = "ZERO"
        Units = "ZERO"

        Dim strAmt As String = Amt.ToString.Trim
        Dim CharVal As String = ""
        Dim UnitCount As Integer = 0
        Dim tmpWord As String = ""

        Do Until String.IsNullOrEmpty(strAmt)

            UnitCount += 1
            CharVal = Strings.Right(strAmt, 1)
            strAmt = Strings.Left(strAmt, Len(strAmt) - 1)

            tmpWord = GetWord(CharVal)

            Select Case UnitCount
                Case 1
                    Units = tmpWord
                Case 2
                    Tens = tmpWord
                Case 3
                    Hundreds = tmpWord
                Case 4
                    Thousands = tmpWord
                Case 5
                    TenThousands = tmpWord
                Case 6
                    HundredThousands = tmpWord
                Case 7
                    Millions = tmpWord

                Case Else
                    MessageBox.Show("Problem")

            End Select


        Loop




    End Sub


    Private Function GetWord(ByVal CharVal As String) As String
        Dim strWord As String = ""
        Select Case CharVal
            Case "1"
                strWord = "ONE"
            Case "2"
                strWord = "TWO"
            Case "3"
                strWord = "THREE"
            Case "4"
                strWord = "FOUR"
            Case "5"
                strWord = "FIVE"
            Case "6"
                strWord = "SIX"
            Case "7"
                strWord = "SEVEN"
            Case "8"
                strWord = "EIGHT"
            Case "9"
                strWord = "NINE"
            Case "0"
                strWord = "ZERO"
            Case Else
                strWord = "*ZERO*"
        End Select

        GetWord = strWord
    End Function
0
 
LVL 1

Expert Comment

by:Eamon
Comment Utility
sorry ignore that. Just noticed it was not .net.
SORRY
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 36

Expert Comment

by:Geert Gruwez
Comment Utility
VB code in Delphi Programming ?
0
 

Author Comment

by:Whisper700
Comment Utility
Geert,
I'm not familiar with loading DLLS using delphi. Can you please show me an example of how to load and use that DLL provided in http://www.mygoldensoft.com/features/num2text.htm.

Thanks
0
 

Author Comment

by:Whisper700
Comment Utility
Can't someone tell me how to use this dll found here http://www.mygoldensoft.com/features/num2text.htm with delphi?
0
 
LVL 45

Expert Comment

by:aikimark
Comment Utility
my $.02

The "AND" is supposed to separate the dollars from the cents.

"TEN MILLION THREE DOLLARS" is correct.
0
 
LVL 36

Expert Comment

by:Geert Gruwez
Comment Utility
>>Whipser700
sorry for nothing getting back to the Q rapidly

I tried several ways to get the dll working
Import ActiveX library
Import Type Library

manually using the dll with code (see snippet)

nothing worked,
now i'm still waiting on a return mail from the vendor ...


function TranslateNumber(str_Number: string; Lang: integer): string; stdcall;

procedure SetCurrency(str_Currency, str_CurrencyUnit, str_CurrencyPlural, str_CurrencyUnitPlural: string); stdcall;
 

implementation
 

const Num2TextLib = 'c:\windows\system32\DC_Num2Text10.dll';
 

function TranslateNumber; external Num2TextLib name 'TranslateNumber';

procedure SetCurrency; external Num2TextLib name 'TranslateNumber';

Open in new window

0
 
LVL 36

Expert Comment

by:Geert Gruwez
Comment Utility
oops probably an error :

procedure SetCurrency; external Num2TextLib name 'SetCurrency';
0
 
LVL 36

Expert Comment

by:Geert Gruwez
Comment Utility
hey man,
I got a response, kind of an ugly one :<

Dear Geert
 
we apologize , but this is a COM registeration problem , this is beyond our support.
 
please refer to delphi text books & web sites committee
 
 
Thank you
 
Mohamed
My GoldenSoft Support Team
www.mygoldensoft.com
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Convert Jpg /PNG To GIF 5 101
code issue 8 84
Delphi selector screen 2 56
tidtcpserver connection lost handle 2 41
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now