source:
trunk/essentials/sys-apps/gawk/test/addcomma.awk
Last change on this file was 3076, checked in by , 18 years ago | |
---|---|
File size: 426 bytes |
Line | |
---|---|
1 | # addcomma - put commas in numbers |
2 | # input: a number per line |
3 | # output: the input number followed by |
4 | # the number with commas and two decimal places |
5 | |
6 | { printf("%-12s %20s\n", $0, addcomma($0)) } |
7 | |
8 | function addcomma(x, num) { |
9 | if (x < 0) |
10 | return "-" addcomma(-x) |
11 | num = sprintf("%.2f", x) # num is dddddd.dd |
12 | while (num ~ /[0-9][0-9][0-9][0-9]/) |
13 | sub(/[0-9][0-9][0-9][,.]/, ",&", num) |
14 | return num |
15 | } |
Note:
See TracBrowser
for help on using the repository browser.