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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need function to convert numbers to words. like on a check.

Status
Not open for further replies.

JerMyster

IS-IT--Management
Mar 17, 2003
49
US
Looking for a function that will convert a number to words. Example: $ 1,550.50 need to convert to ********One Thousand Five Hundred Fifty Dollars and 50/100

Thanks
 
check out FAQ faq184-2848


num to words program in the utility section

(can't work out how to paste the shortcut)

modify the cents/dollar bit to get the format you want - In the UK we use "and 99 pence" rather than 99/100

mr F
 
JerMyster,

Have you got 1001 Things You Wanted to Know About Visual Foxpro? The function you want is on page 46 (it is surprisingly long; it runs to four pages).

You can find more details of the above book on my web site, at

Mike


Mike Lewis
Edinburgh, Scotland
 
There's a class available at that seems to do what you're after too.

h,

Andrew

Andrew Coates
OzFox 2003 Australia's VFP Conference -- ------
DISCLOSURE
We are the Australasian Distributor for the Hentzenwerke Series of Books. (By the same token, I really do think they're the best printed VFP resource out there -- that's why we sell them)
 
This reminder me of the olden days of the DOS world. I got these library codes that I used for my customized business applications. Here's the codes:

************************************************
*dollar.prg
*Larry - 5-Mar-1999

proc dollar &&for procedure file; remark this line for standalone file.
* spell amount in english
para m
priv n,s
if m=0
retu 'ZERO ONLY'
endif
dime den(4)
den(1)=''
den(2)=' THOUSAND'
den(3)=' MILLION'
den(4)=' BILLION'
cent=(m-int(m))*100
m=int(m)
s=''
n=0

do while m>0
n=n+1
s= hnds( mod(m,1000) ) + den(n) + s
m=int(m/1000)
enddo

if cent>0
s=trim(s) +' AND CENTS'+ hnds(cent)
endif
*if ' '$s
* s=stuff(s,at(' ',s),2,' ')
* endif
retu alltrim(s) + ' ONLY'

func tens
para m
retu ' '+trim( subs('ONE TWO THREEFOUR FIVE SIX SEVENEIGHTNINE',m*5-4,5) )

func hnds
para m
priv s1
s1=''
if m>99
s1= tens(int(m/100)) + ' HUNDRED'
m = mod(m,100)
endif

if m>=20
s1= s1 +' '+ trim( subs(' TWENTY THIRTY FORTY FIFTY SIXTY SEVENTYEIGHTY NINETY',int(m/10)*7-6,7) )
m = mod(m,10)
else
if m>=10
m = m-10
s1= s1 +' '+ trim( subs('TEN ELEVEN TWELVE THIRTEEN FORTEEN FIFTEEN SIXTEEN SEVENTEENEIGHTEEN NINETEEN',m*9+1,9) )
m = 0
endif
endif

if m>0
s1= s1+tens(m)
m = 0
endif
retu trim(s1)
************************************************
In VFP:
?'AMOUNT: '+dollar(1234.50)

Result:
AMOUNT: ONE THOUSAND TWO HUNDRED THIRTY FOUR AND CENTS FIFTY ONLY.

Limits:
This code works up to Billions.

Free for use.
Larry
 
Nice to see you're making your checks as safe as possible.

Better than certain unnamed government(s) who after all these years still don't print the amount in words on their checks! (Hey, obviously just a rhetorical question, no reply expected.) A number-to-words program was something I wrote back in the 1980s as a novice programmer. In the past forgers have had a field day altering checks where just a swapped digit makes a big difference. (Some have said it's not their hard-earned money so they don't care much, what's a fraction of a percent anyway?)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top