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

  1. ############################################################################
  2. #
  3. #    Name:     commaize.icn
  4. #
  5. #    Title:     commaize real or integer (or string equivalents)
  6. #
  7. #    Author:     Ralph Griswold and Richard L. Goerwitz
  8. #
  9. #    Version: 1.1
  10. #
  11. ############################################################################
  12. #  
  13. #  Comma-izes reals or integers (e.g. -1040.39 -> "-1,040.39").
  14. #
  15. ############################################################################
  16. #
  17. #  Links:  none
  18. #
  19. ############################################################################
  20.  
  21.  
  22. procedure commaize(s)
  23.  
  24.     local s2, sign
  25.  
  26.     # Don't bother if s is already comma-ized.
  27.     if type(s) == "string" then find(",", s) & fail
  28.  
  29.     # Take sign.  Save chars after the decimal point (if present).
  30.     if s := abs(0 > s)
  31.     then sign := "-" else sign := ""
  32.     s ? {
  33.     s := tab(find(".")) & ="." &
  34.     not pos(0) & s2 := "." || integer(tab(0))
  35.     }
  36.  
  37.     /s2 := ""
  38.     integer(s) ? {
  39.     tab(0)
  40.     while s2 := "," || move(-3) || s2
  41.     if pos(1)
  42.     then s2 ?:= (move(1), tab(0))
  43.     else s2 := tab(1) || s2
  44.     }
  45.     return sign || s2
  46.  
  47. end
  48.  
  49.  
  50.