Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Converting Amount to Words (12.20 =twelve Rs twenty Ps)
Message
 
To
07/08/2002 10:22:55
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00687042
Message ID:
00687095
Views:
10
Its long, but here's the code:
************************************************************
*  METHOD: Procedures.Amt2String
* PURPOSE: Converts a dollar amount to a character string
*  PARAMS: nAmt	- Amount to be converted
* RETURNS: Character - Dollar amount in words
*
************************************************************
LPARAMETER nAmt

private eng_end,temp,iloop
local Temp200

dimension arr(19)
dimension arr2(8)

store 'One' 		to arr(1)
store 'Two' 		to arr(2)
store 'Three' 		to arr(3)
store 'Four' 		to arr(4)
store 'Five' 		to arr(5)
store 'Six' 		to arr(6)
store 'Seven' 		to arr(7)
store 'Eight' 		to arr(8)
store 'Nine'  		to arr(9)
store 'Ten' 		to arr(10)
store 'Eleven' 		to arr(11)
store 'Twelve' 	to arr(12)
store 'Thirteen' 	to arr(13)
store 'Fourteen' 	to arr(14)
store 'Fifteen' 	to arr(15)
store 'Sixteen' 	to arr(16)
store 'Seventeen'	to arr(17)
store 'Eighteen' 	to arr(18)
store 'Nineteen' 	to arr(19)
store 'Twenty' 	to arr2(1)
store 'Thirty' 	to arr2(2)
store 'Forty'  	to arr2(3)
store 'Fifty'  		to arr2(4)
store 'Sixty'  	to arr2(5)
store 'Seventy' 	to arr2(6)
store 'Eighty' 	to arr2(7)
store 'Ninety'  	to arr2(8)

store space(70) to cReturnString

store 'Dollars & xx Cents' to eng_end
store space(2) to temp2
store space(1) to temp1

Temp200 = int(namt)
Temp200 = (namt - Temp200) * 100
cReturnString = stuff(eng_end,11,2,str(Temp200,2,0))
cReturnString = alltrim(cReturnString)

Temp200 = int(namt)

store space(8) to temp8
temp8 = str(Temp200,8,0)

  temp2 = substr(temp8,7,2)

  Temp2001 = val(temp2)
  do case
  case Temp2001 >= 1 .and. Temp2001 < 20
    cReturnString = arr(Temp2001) + ' ' + cReturnString
  case Temp2001 >= 20 .and. Temp2001 <= 99
    temp1 = substr(temp2,2,1)
    Temp2002 = val(temp1)
    if Temp2002 > 0
      cReturnString = arr(Temp2002) + ' ' + cReturnString
    endif
    temp1 = substr(temp2,1,1)
    Temp2002   = val(temp1) - 1
    cReturnString = arr2(Temp2002) + ' ' + cReturnString
  endcase
*
* 100's
*
  temp1 = substr(temp8,6,1)
  Temp2001 = val(temp1)
  if Temp2001 >= 1 .and. Temp2001 <= 9
    cReturnString = arr(Temp2001) + ' ' + 'Hundred ' + cReturnString
  endif
*
* 1000
*
  temp2 = substr(temp8,4,2)

  ithou = .f.
  Temp2001 = val(temp2)
  do case
  case Temp2001 >= 1 .and. Temp2001 < 20
    cReturnString = arr(Temp2001) + ' Thousand ' + cReturnString
    ithou = .t.
  case Temp2001 >= 20 .and. Temp2001 <= 99
    temp1 = substr(temp2,2,1)
    Temp2002 = val(temp1)
    if Temp2002 > 0
      cReturnString = arr(Temp2002) + ' Thousand ' + cReturnString
      ithou = .t.
    endif
    temp1 = substr(temp2,1,1)
    Temp2002   = val(temp1) - 1
    if .not. ithou
      cReturnString = ' Thousand ' + cReturnString
    endif
    cReturnString = arr2(Temp2002) + ' ' + cReturnString
    ithou = .t.
  endcase

  temp1 = substr(temp8,3,1)
  Temp2001 = val(temp1)
  if Temp2001 >= 1 .and. Temp2001 <= 9
    if .not. ithou
      cReturnString = ' Thousand ' + cReturnString
    endif
    cReturnString = arr(Temp2001) + ' ' + 'Hundred ' + cReturnString
  endif

if namt > 0 .and. namt < 1
  cReturnString = 'Zero ' + cReturnString
endif

if namt <= 0
  cReturnString = REPLICATE('*', 70)
endif

return cReturnString
Everything makes sense in someone's mind
public class SystemCrasher :ICrashable
In addition, an integer field is not for irrational people
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform