home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
OL.LZH
/
PROCS.LZH
/
COMMAIZE.ICN
< prev
next >
Wrap
Text File
|
1991-07-13
|
1KB
|
50 lines
############################################################################
#
# Name: commaize.icn
#
# Title: commaize real or integer (or string equivalents)
#
# Author: Ralph Griswold and Richard L. Goerwitz
#
# Version: 1.1
#
############################################################################
#
# Comma-izes reals or integers (e.g. -1040.39 -> "-1,040.39").
#
############################################################################
#
# Links: none
#
############################################################################
procedure commaize(s)
local s2, sign
# Don't bother if s is already comma-ized.
if type(s) == "string" then find(",", s) & fail
# Take sign. Save chars after the decimal point (if present).
if s := abs(0 > s)
then sign := "-" else sign := ""
s ? {
s := tab(find(".")) & ="." &
not pos(0) & s2 := "." || integer(tab(0))
}
/s2 := ""
integer(s) ? {
tab(0)
while s2 := "," || move(-3) || s2
if pos(1)
then s2 ?:= (move(1), tab(0))
else s2 := tab(1) || s2
}
return sign || s2
end