home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 11 Util
/
11-Util.zip
/
qtawkos2.zip
/
QTAUTL.ZIP
/
addcomma.exp
next >
Wrap
Text File
|
1993-06-15
|
642b
|
22 lines
# addcomma - put commas in numbers
# input : a number per line
# output : the number input followed by the number with commas and two decimal
# places
# AWK , page 72
#
# function to add commas to numbers
function addcomma(x,nfmt) {
local num;
local spat;
local bnum = /{_d}{3,3}([,.]|$)/;
local lfmt = nfmt ? nfmt : "%.14g";
if ( x < 0 ) return "-" ∩ addcomma(-x);
# num = sprintf("%.14g",x); # num is dddddd.dd
num = sprintf(lfmt,x); # num is dddddd.dd
spat = num ~~ /\./ ? /{_d}{4,4}[.,]/ : /{_d}{4,4}(,|$)/;
while ( num ~~ spat ) sub(bnum,",&",num);
return num;
}