Hi all.
Anyway since this thread refers to it, I had this
which works for money type formatting in awk.
function stupidround(calc, what,x) {
if (x = split(calc,what,"."

> 0) {
if (substr(what[2],1,1) == 3) {
return "1"
} else if (substr(what[2],1,1) == 6) {
return "2"
}
} else {
return "3"
}
}
function shortstuf(str) {
return substr(str,1,length(str))".00"
}
function decision(str,m1, x,all) {
all = substr(str,1,m1)
x = (1 + m1)
while (x <= length(str)) {
all = all "," substr(str,x,3)
x = x + 3
}
#ugly..but you fix it.
all = all".00" ; sub(/^,/,"",all)
return all
}
function dim(str, dd) {
if (length(str) <= 3) {
return shortstuf(str)
}
dd = stupidround((length(str) / 3))
return decision(str,dd)
}
BEGIN {
a = dim(ARGV[1])
print a
}
Sample run:
:~ > awk -f awkstuff/money.awk 3783903
3,783,903.00
:~ > awk -f awkstuff/money.awk 37839
37,839.00
:~ > awk -f awkstuff/money.awk 3783
3,783.00