Welcome To The Home Of The Visual FoxPro Experts  
home. signup. forum. archives. search. google. articles. downloads. faq. members. weblogs. file info. rss.
 From: Rene Relucio
  Where is Rene Relucio?
 Quezon City
 Philippines
 Rene Relucio
 Tags
Subject: Converting your numeric figures in words
Thread ID: 11435 Message ID: 11435 # Views: 35 # Ratings: 0
Version: Unknown Category: General VFP Topics
Date: Wednesday, June 05, 2002 12:10:16 PM         
   


*This program will convert your numeric figures in words.
*Good for check writing.
*Ex. usage:  ? INWORDS(10450.60)
*If you have other currency in words, change "dollar" 
*with your currency in the program.

parameter AMT
if AMT <= 0
   return "** V O I D **"
endif

if AMT >= 10000000000
   return "Cannot Print 10 billion over!"
endif

RDIG = ""
CAMT = alltrim(str(int(amt)))
LENUM = len(CAMT)

dimension CDIG(LENUM), W19(19), WTY(9)
do INIT19
do INITTY

for J = LENUM to 1 step -1
    RDIG = RDIG + substr(CAMT,J,1)
endfor

for J = 1 to LENUM
    CDIG(J) = val(substr(RDIG,J,1))
endfor

AMTWORDS = ""
MCTR = 0

for J = 1 to LENUM
    INWORDS = ""
    if CDIG(J) <> 0
       do case
          case mod(J,3) = 1
               if J+1 > LENUM
                  INWORDS = W19(CDIG(J))
               else
                  if CDIG(J+1) <> 1
                     INWORDS = W19(CDIG(J))
                  endif
               endif
          case mod(J,3) = 2
               if CDIG(J)*10 + CDIG(J-1) < 20 and ;
                  CDIG(J)*10 + CDIG(J-1) > 0
                  INWORDS = W19(CDIG(J)*10+CDIG(J-1))
               else
                  INWORDS = WTY(CDIG(J))
               endif
          otherwise
               INWORDS = W19(CDIG(J))+" Hundred"
       endcase
    endif
    AMTWORDS = alltrim(INWORDS + " " + alltrim(AMTWORDS))
    if mod(J,3) = 0 
       if J = LENUM 
          exit
       endif
       MCTR = MCTR + 1
       if val(substr(RDIG,J+1,min(LENUM-J,3))) <> 0
          do case
             case MCTR = 1
                  AMTWORDS = " Thousand "+AMTWORDS
             case MCTR = 2
                  AMTWORDS = " Million "+AMTWORDS
             case MCTR = 3
                  AMTWORDS = " Billion "+AMTWORDS
          endcase
       endif
    endif
endfor

if AMT <= 0
   return "*** V O I D ***"
else
   return AMTWORDS+" Dollars"+iif(int(AMT)=AMT," Only"," & " + ;
                             right(str(AMT,15,2),2)+"/100")
endif

proc INIT19
W19(1) = "One"
W19(2) = "Two"
W19(3) = "Three"
W19(4) = "Four"
W19(5) = "Five"
W19(6) = "Six"
W19(7) = "Seven"
W19(8) = "Eight"
W19(9) = "Nine"
W19(10)= "Ten"
W19(11)= "Eleven"
W19(12)= "Twelve"
W19(13)= "Thirteen"
W19(14)= "Fourteen"
W19(15)= "Fifteen"
W19(16)= "Sixteen"
W19(17)= "Seventeen"
W19(18)= "Eighteen"
W19(19)= "Nineteen"


proc INITTY
WTY(1) = ""
WTY(2) = "Twenty"
WTY(3) = "Thirty"
WTY(4) = "Forty"
WTY(5) = "Fifty"
WTY(6) = "Sixty"
WTY(7) = "Seventy"
WTY(8) = "Eighty"
WTY(9) = "Ninety"



COMPLETE THREAD

Converting your numeric figures in words Posted by RENE RELUCIO @ 6/5/2002 12:10:16 PM
RE: Converting your numeric figures in words Posted by Karben Selim Mejia (MejiaKS) @ 6/5/2002 4:39:18 PM