home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / OL.LZH / PROCS.LZH / CURRENCY.ICN < prev    next >
Text File  |  1991-07-13  |  1KB  |  40 lines

  1. ############################################################################
  2. #
  3. #    Name:    currency.icn
  4. #
  5. #    Title:    Currency formatting procedure
  6. #
  7. #    Author:    Robert J. Alexander
  8. #
  9. #    Date:    December 5, 1989
  10. #
  11. ############################################################################
  12. #
  13. #  currency() -- Formats "amount" in standard American currency format.
  14. #  "amount" can be a real, integer, or numeric string.  "width" is the
  15. #  output field width, in which the amount is right adjusted.  The
  16. #  returned string will be longer than "width" if necessary to preserve
  17. #  significance.  "minus" is the character string to be used for
  18. #  negative amounts (default "-"), and is placed to the right of the
  19. #  amount.
  20. #
  21. ############################################################################
  22.  
  23. procedure currency(amount,width,minus)
  24.    local sign,p
  25.    /width := 0
  26.    /minus := "-"
  27.    amount := real(amount) | fail
  28.    if amount < 0 then {
  29.       sign := minus
  30.       amount := -amount
  31.       }
  32.    else sign := repl(" ",*minus)
  33.    amount := string(amount)
  34.    amount := if p := find(".",amount) then left(amount,p + 2,"0") else
  35.      amount || ".00"
  36.    if match("0.",amount) then amount[1:3] := "0."
  37.    amount := "$" || amount || sign
  38.    return if *amount >= width then amount else right(amount,width)
  39. end
  40.