There are quite a few functions that are available on the net.
I have one written by Paul Vlad Tatavu that takes numbers and changes them to words, but doesn't really deal with the currency part, since that is more specific to a particular country. If you are interested, give me your e-mail address.
Copy the following to the end of your main.prg.
**********************************************************
FUNCTION numtoword
PARAMETER amt
amt = ABS(amt)
nDecimal = SET("DECIMAL"
SET DECIMALS TO 18
m.numphrase = " "
IF INT(amt / 1000000) > 0 && Amount in millions?
m.numphrase = m.numphrase + numword(INT(amt/1000000))+ ;
" Million "
ENDIF
IF INT(amt / 1000) > 0 && Amount in thousands?
m.numphrase = m.numphrase + ;
numword(MOD(INT(amt / 1000),1000))+" Thousand "
ENDIF
m.numphrase = ;
ALLTRIM(m.numphrase + numword(MOD(INT(amt),1000)))
m.cent = MOD(amt * 100, 100) && Get decimal
IF m.cent > 0
m.numphrase = ALLTRIM(m.numphrase) + " and " + ;
ALLTRIM(STR(m.cent)) + "/100"
ENDIF
IF LEN(ALLTRIM(m.numphrase)) > 1
m.numphrase = m.numphrase + " Only."
ENDIF
SET DECIMALS TO nDecimal
RETURN m.numphrase
*********************************************************
** Called by: numtoword()
*********************************************************
FUNCTION numword
PARAMETER amt
DECLARE one[10]
DECLARE ten[10]
DECLARE teen[10]
I have done similar routines number of times in different ways and I have copied routines as well from some BBSs. I sincerely dont remember everything in here is mine, since this is from my long time library. Credits to those who helped make the above.
Heh...I did a similar routine in QuickBASIC back in '92 for a business class I was in. I think I only took the numbers into the thousands, though. And that code is LONG gone.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.