INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Utility Program

A Number to word convertion Utility by ramani
Posted: 5 Dec 02 (Edited 26 Aug 03)

*********************************************************
** Author   : Ramani (Subramanian.G)
**           áFoxAcc Software / Winners Software
**            www.winnersoft.coolfreepages.com
** Type    á: Freeware with reservation to Copyrights
** Warranty : Nothing implied or explicit
** Last modified : June, 2003
*********************************************************
** How to Run..
** 1. Save the following code as Num2Word.PRG
** 2. From within your PRG or Report call it as
** áááNum2Word(nYourAmount)
*********************************************************
** Modify decimal places suitably, if > 2 decimals required
*********************************************************
** FUNCTION num2word
LPARAMETER amt
amt = ABS(amt)

IF amt > 999999999999.99 && => 1000 billion
   =MESSAGEBOX("Amount exceeds word convertion provision. Contact system administrator", ;
      0+16, "CAUTION. Check total amount !")
ENDIF
IF amt = 0
   RETURN "Zero Only."
ENDIF

** used by Function numWord
PRIVATE pcWord1, pcWord2, pcWord3, pcWord4, pcWord5, pcWord6, pcWord7, ;
   pcWord8, pcWord9, pcWord10, pcWord11, pcWord12, pcWord13, pcWord14, ;
   pcWord15, pcWord16, pcWord17, pcWord18, pcWord19, pcWord20, pcWord30, ;
   pcWord40, pcWord50, pcWord60, pcWord70, pcWord80, pcWord90
pcWord1 = "One "
pcWord2 = "Two "
pcWord3 = "Three "
pcWord4 = "Four "
pcWord5 = "Five "
pcWord6 = "Six "
pcWord7 = "Seven "
pcWord8 = "Eight "
pcWord9 = "Nine "
pcWord10 = "Ten "
pcWord11 = "Eleven "
pcWord12 = "Twelve "
pcWord13 = "Thirteen "
pcWord14 = "Fourteen "
pcWord15 = "Fifteen "
pcWord16 = "Sixteen "
pcWord17 = "Seventeen "
pcWord18 = "Eighteen "
pcWord19 = "Ninteen "
pcWord20 = "Twenty "
pcWord30 = "Thirty "
pcWord40 = "Forty "
pcWord50 = "Fifty "
pcWord60 = "Sixty "
pcWord70 = "Seventy "
pcWord80 = "Eighty "
pcWord90 = "Ninety "
**
LOCAL lcNumPhrase, lcNumStr

m.lcNumphrase = ""
m.lcNumStr = STR(amt,17,4)

IF VAL(SUBSTR(m.lcNumStr,1,3)) > 0    && Amount in Billions
   m.lcNumphrase = m.lcNumphrase + Numword(SUBSTR(m.lcNumStr,1,3)) + ;
      " Billion "
ENDIF

IF VAL(SUBSTR(m.lcNumStr,4,3)) > 0     && Amount in millions
   m.lcNumphrase = m.lcNumphrase + Numword(SUBSTR(m.lcNumStr,4,3)) + ;
      " Million "
ENDIF

IF VAL(SUBSTR(m.lcNumStr,7,3)) > 0    && Amount in thousands
   m.lcNumphrase = m.lcNumphrase + Numword(SUBSTR(m.lcNumStr,7,3)) + ;
      " Thousand "
ENDIF

IF VAL(SUBSTR(m.lcNumStr,10,3)) > 0    && Amount below thousands
   m.lcNumphrase = m.lcNumphrase + Numword(SUBSTR(m.lcNumStr,10,3))
ENDIF

IF VAL(SUBSTR(m.lcNumStr,14,2)) > 0    && Amount in Decimals
    ** needs tingering depending on digits - Default is 2 decimals
   IF LEN(ALLTRIM(m.lcNumphrase)) > 1
      m.lcNumphrase = ALLTRIM(m.lcNumphrase) + " and "
   ELSE
      m.lcNumphrase = "Zero and "
   ENDIF
   m.lcNumphrase = m.lcNumphrase + SUBSTR(m.lcNumStr,14,2) + "/100"
ENDIF

IF LEN(ALLTRIM(m.lcNumphrase)) > 1
   m.lcNumphrase = ALLTRIM(m.lcNumphrase) + " Only."
ENDIF

RETURN m.lcNumphrase
*********************************************************
** Called by: numtoword() (function  in NUMWORD.PRG)
*********************************************************
FUNCTION numword
   LPARAMETERS tStr

   LOCAL lnStr, lcPhrase, lcStr
   lcPhrase = " "
   lnStr = VAL(tStr)

   ** Hundredth position
   IF lnStr > 99
      lcStr = LEFT(tStr,1)
      lcPhrase = pcWord&lcStr + "Hundred "
   ENDIF

   ** Balance Position
   lnStr = VAL(RIGHT(tStr,2))
   IF BETWEEN(lnStr,1,20)
      lcStr = ALLTRIM(STR(lnStr))
      lcPhrase = lcPhrase + pcWord&lcStr
   ENDIF
   IF BETWEEN(lnStr,21,99)
      IF lnStr > 20
         lcStr = SUBSTR(tStr,2,1)+"0"
         lcPhrase = lcPhrase + pcWord&lcStr
      ENDIF
      IF RIGHT(tStr,1) > '0'
         lcStr = RIGHT(tStr,1)
         lcPhrase = lcPhrase + pcWord&lcStr
      ENDIF
   ENDIF   
   RETURN ALLTRIM(lcPhrase)
*********************************************************
* EOF: NUM2WORD.PRG
*********************************************************

Back to Microsoft: Visual FoxPro FAQ Index
Back to Microsoft: Visual FoxPro Forum

My Archive

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close