home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 5 / 05.iso / a / a067 / 1.img / GRUMP501.EXE / AMT2CHR.PRG < prev    next >
Encoding:
Text File  |  1991-04-23  |  1.9 KB  |  70 lines

  1. /*
  2.     Program: Amt2Chr()
  3.     System: GRUMPFISH LIBRARY
  4.     Author: Greg Lief
  5.     Copyright (c) 1988-90, Greg Lief
  6.     Clipper 5.x version
  7.     Compile instructions: clipper $amt2chr /n/w/a
  8.  
  9.     Convert numeric to character-string (dollar format), great for
  10.     writing checks (make 'em payable to Grumpfish, Inc.)
  11. */
  12. function Amt2Chr(namount)
  13. local cstring := '', temp, xx
  14. for xx := 6 to 0 step -3
  15.    if namount >= 10 ^ xx
  16.       temp := int(namount / 10 ^ xx)
  17.       cstring += convert_it(temp) + if(xx = 6, ' million', ;
  18.                 if(xx = 3, ' thousand', ''))
  19.       namount -= temp * 10 ^ xx
  20.       if namount > 0
  21.          cstring += ' '
  22.       endif
  23.    endif
  24. next
  25. if namount != int(namount)
  26.    cstring += 'and ' + str((namount - int(namount)) * 100, 2) + '/100ths'
  27. else
  28.    cstring += ' exactly'
  29. endif
  30. return cstring
  31.  
  32. * end function Amt2Chr()
  33. *--------------------------------------------------------------------*
  34.  
  35.  
  36. /*
  37.    Static Function: CONVERT_IT()
  38. */
  39. static function convert_it(namount)
  40. static words := {'One', 'Two', 'Three', 'Four', 'Five', 'Six', 'Seven', ;
  41.       'Eight', 'Nine', 'Ten', 'Eleven', 'Twelve', 'Thirteen', 'Fourteen', ;
  42.       'Fifteen', 'Sixteen', 'Seventeen', 'Eighteen', 'Nineteen', 'Twenty', ;
  43.       'Thirty', 'Forty', 'Fifty', 'Sixty', 'Seventy', 'Eighty', 'Ninety'}
  44. local cstring := '', temp
  45. if namount > 99
  46.    temp := int(namount / 100)
  47.    cstring += words[temp] + ' hundred'
  48.    namount -= temp * 100
  49.    if namount > 0
  50.       cstring += ' '
  51.    endif
  52. endif
  53. do case
  54.    case namount > 0 .and. namount < 20
  55.       cstring += words[namount]
  56.    case namount > 19
  57.       temp := int(namount / 10)
  58.       cstring += words[temp + 18]
  59.       namount -= temp * 10
  60.       if namount != 0
  61.          cstring += '-' + words[namount]
  62.       endif
  63. endcase
  64. return cstring
  65.  
  66. * end static function Convert_It()
  67. *--------------------------------------------------------------------*
  68.  
  69. * eof amt2chr.prg
  70.