Information générale
Catégorie:
Codage, syntaxe et commandes
Bonjour Roy. Comment ca va?
The following function I have used for years from clipper through VFP.
Simply pass the numeric dollar amount to the function and the words will be returned.
Good Luck
Bruce
function numwords
PARAMETERS mamt
* Initialize memory variables
camt1=""
STORE " ONE TWO THREEFOUR FIVE SIX SEVENEIGHTNINE " TO ones
STORE "TEN ELEVEN TWELVE THIRTEEN FOURTEEN FIFTEEN SIXTEEN "+;
"SEVENTEENEIGHTEEN NINETEEN " TO teen
STORE "TWENTY THIRTY FORTY FIFTY SIXTY SEVENTYEIGHTY NINETY" TO tens
* Store whole dollar amount to a string
cnum=LEFT(STR(mamt,9,2),6)
* check hundreds of thousands
IF LEFT(cnum,1)>" "
camt1=RTRIM(SUBSTR(ones,VAL(LEFT(cnum,1))*5+1,5))+" HUNDRED "
ENDIF
* check tens of thousands and thousands
DO CASE
CASE SUBSTR(cnum,2,1)>"1"
camt1=camt1+RTRIM(SUBSTR(tens,VAL(SUBSTR(cnum,2,1))*7-13,7))
IF SUBSTR(cnum,3,1)>"0"
camt1=camt1+"-"+RTRIM(SUBSTR(ones,VAL(SUBSTR(cnum,3,1))*5+1,5))
ENDIF
camt1=camt1+" THOUSAND "
CASE SUBSTR(cnum,2,1)="1"
camt1=camt1+RTRIM(SUBSTR(teen,VAL(SUBSTR(cnum,3,1))*9+1,9))+" THOUSAND "
CASE SUBSTR(cnum,2,2)="00"
camt1=camt1+"THOUSAND "
CASE SUBSTR(cnum,3,1)>" "
camt1=camt1+RTRIM(SUBSTR(ones,VAL(SUBSTR(cnum,3,1))*5+1,5))+" THOUSAND "
ENDCASE
* check hundreds
IF SUBSTR(cnum,4,1)>"0"
camt1=camt1+RTRIM(SUBSTR(ones,VAL(SUBSTR(cnum,4,1))*5+1,5))+" HUNDRED "
ENDIF
* check tens and ones
DO CASE
CASE SUBSTR(cnum,5,1)>"1"
camt1=camt1+RTRIM(SUBSTR(tens,VAL(SUBSTR(cnum,5,1))*7-13,7))
IF RIGHT(cnum,1)>"0"
camt1=camt1+"-"+RTRIM(SUBSTR(ones,VAL(RIGHT(cnum,1))*5+1,5))
ENDIF
CASE SUBSTR(cnum,5,1)="1"
camt1=camt1+RTRIM(SUBSTR(teen,VAL(RIGHT(cnum,1))*9+1,9))
CASE RIGHT(cnum,2)=" 0"
camt1="ZERO"
OTHERWISE
camt1=camt1+RTRIM(SUBSTR(ones,VAL(RIGHT(cnum,1))*5+1,5))
ENDCASE
* Convert decimal places to a string containing cents amount
cents=RIGHT(STR(mamt,9,2),2)
camt1=RTRIM(camt1)+" AND "+cents+"/100 DOLLARS"
return(camt1)
Précédent
Répondre
Voir le fil de ce thread
Voir le fil de ce thread à partir de ce message seulement
Voir tous les messages de ce thread
Voir tous les messages de ce thread à partir de ce message seulement