Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I convert currency value to characters? 1

Status
Not open for further replies.

Werewolf

Programmer
May 20, 2002
3
US
Hi there:

I have some currency values in the report that I must display in characters format.

E.g. $ 20.40 to Dollars twenty and Cents forty Only.

Is there any way? Please help! Thanks & Regards!
 
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.
 
Hi

myAmount = nnnnnnnnn.nnnn
AmountInWord = NumToWord(myAmount)

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]

one[1] = "One"
one[2] = "Two"
one[3] = "Three"
one[4] = "Four"
one[5] = "Five"
one[6] = "Six"
one[7] = "Seven"
one[8] = "Eight"
one[9] = "Nine"
ten[1] = "Ten"
ten[2] = "Twenty"
ten[3] = "Thirty"
ten[4] = "Fourty"
ten[5] = "Fifty"
ten[6] = "Sixty"
ten[7] = "Seventy"
ten[8] = "Eighty"
ten[9] = "Ninety"
teen[1] = "Eleven"
teen[2] = "Twelve"
teen[3] = "Thirteen"
teen[4] = "Fourteen"
teen[5] = "Fifteen"
teen[6] = "Sixteen"
teen[7] = "Seventeen"
teen[8] = "Eighteen"
teen[9] = "Ninteen"
m.hundred = INT(amt/100) && Get decimal position 1
IF m.hundred > 0
m.numphrase = one[m.hundred] + " Hundred "
ELSE
m.numphrase = " "
ENDIF
m.decpos2 = MOD(amt, 100) && Get decimal position 2
m.decpos3 = INT(m.decpos2/10) && Get decimal position 3
IF m.decpos2 >= 11 AND m.decpos2 <= 19 && Number in teens?
m.numphrase = m.numphrase + teen[INT(MOD(m.decpos2, 10))]
ELSE && Not in teens
IF m.decpos3 > 0
m.numphrase = m.numphrase + ten[INT(m.decpos2 / 10)]
ENDIF
IF MOD(m.decpos2, 10) > 0
m.numphrase = ALLTRIM(m.numphrase) + &quot; &quot; + ;
one[MOD(m.decpos2, 10)]
ENDIF
ENDIF
RETURN ALLTRIM(m.numphrase)
*********************************************************
* EOF: NUMWORD
*********************************************************

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. :)


ramani :)
(Subramanian.G),FoxAcc, ramani_g@yahoo.com
 
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.

Ian
 
Hi guys:

Thanks for the tips. Really appreciate your help. Thanks a million.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top