Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Looking for numbers to words function
Message
From
29/09/1998 16:28:05
 
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
00142062
Message ID:
00142118
Views:
32
This'll do it:

cCheckAmount=Verbalize(nNumber,lTrueFalse)
nNumber = number or currency to convert
lTrueFalse = PROPER case it?
PROCEDURE Verbalize
LPARAMETERS nNum,lPropered
IF !TYPE("nNum")$"NY"
   RETURN
ENDIF
IF TYPE("lPropered")="U"
   lPropered=.F.
ENDIF
=InitArrays(lPropered)
cAmount=""
cNum=STR(nNum,12,2)
cAmount=CvrtBlock(SUBSTR(cNum,7,3),"")+"Dollars and "+ALLT(STR(VAL(RIGHT(cNum,2))))+" Cents"
cAmount=CvrtBlock(SUBSTR(cNum,4,3),"Thousand ")+cAmount
cAmount=CvrtBlock(SUBSTR(cNum,1,3),"Million ")+cAmount
RELEASE aTens,aOnes,aTeens
RETURN cAmount
ENDPROC
* InitArrays -- Initialize arrays
PROCEDURE InitArrays
LPARAMETERS lPropered
PUBLIC aTens[9],aOnes[9],aTeens[9]
aTens[1]="TEN"
aTens[2]="TWENTY"
aTens[3]="THIRTY"
aTens[4]="FORTY"
aTens[5]="FIFTY"
aTens[6]="SIXTY"
aTens[7]="SEVENTY"
aTens[8]="EIGHTY"
aTens[9]="NINETY"
aOnes[1]="ONE"
aOnes[2]="TWO"
aOnes[3]="THREE"
aOnes[4]="FOUR"
aOnes[5]="FIVE"
aOnes[6]="SIX"
aOnes[7]="SEVEN"
aOnes[8]="EIGHT"
aOnes[9]="NINE"
aTeens[1]="ELEVEN"
aTeens[2]="TWELVE"
aTeens[3]="THIRTEEN"
aTeens[4]="FOURTEEN"
aTeens[5]="FIFTEEN"
aTeens[6]="SIXTEEN"
aTeens[7]="SEVENTEEN"
aTeens[8]="EIGHTEEN"
aTeens[9]="NINETEEN"
IF lPropered
   FOR i = 1 TO 9
      aTens[i]=PROPER(aTens[i])
      aOnes[i]=PROPER(aOnes[i])
      aTeens[i]=PROPER(aTeens[i])
   ENDFOR
ENDIF
RETURN
ENDPROC
* CvrtBlock.....converts a 3-character chunk of number   
PROCEDURE CvrtBlock
LPARAMETERS cBlock,cBlockType
cTeens		=""
cOnes			=""
cTens			=""
cHundreds	=""
cConverted  =""
nBValue		= VAL(cBlock)
nTensNOnes  = VAL(RIGHT(cBlock,2))
nDigit		= VAL(RIGHT(cBlock,1))
nDecade     = VAL(SUBSTR(cBlock,2,1))
nCentury    = VAL(LEFT(cBlock,1))
IF nTensNOnes # 0
   IF BETWEEN(nTensNOnes,11,19)
      cTeens=aTeens[nTensNOnes-10]
   ELSE
	   IF MOD(nBValue,10) # 0
	      cOnes=aOnes[nDigit]
	   ENDIF
	   IF nDecade # 0
	      cTens=aTens[nDecade]+IIF(!EMPTY(cOnes),"-","")
	   ENDIF
	ENDIF
ENDIF
IF nCentury # 0
   cHundreds=aOnes[nCentury]+" Hundred "
ENDIF
cConverted=cHundreds+cTeens+cTens+cOnes+" "+cBlockType
RETURN cConverted
ENDPROC
------------------------------------------------
John Koziol, ex-MVP, ex-MS, ex-FoxTeam. Just call me "X"
"When the going gets weird, the weird turn pro" - Hunter Thompson (Gonzo) RIP 2/19/05
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform