1 # prchecks - print formatted checks
2 # input: number \t amount \t payee
3 # output: eight lines of text for preprinted check forms
7 dashes = sp45 = sprintf("%45s", " ")
8 gsub(/ /, "-", dashes) # to protect the payee
9 "date" | getline date # get today's date
11 date = d[2] " " d[3] ", " d[6]
12 initnum() # set up tables for number conversion
14 NF != 3 || $2 >= 1000000 { # illegal data
15 printf("\nline %d illegal:\n%s\n\nVOID\nVOID\n\n\n", NR, $0)
16 next # no check printed
18 { printf("\n") # nothing on line 1
19 printf("%s%s\n", sp45, $1) # number, indented 45 spaces
20 printf("%s%s\n", sp45, date) # date, indented 45 spaces
21 amt = sprintf("%.2f", $2) # formatted amount
22 printf("Pay to %45.45s $%s\n", $3 dashes, amt) # line 4
23 printf("the sum of %s\n", numtowords(amt)) # line 5
24 printf("\n\n\n") # lines 6, 7 and 8
27 function numtowords(n, cents, dols) { # n has 2 decimal places
28 cents = substr(n, length(n)-1, 2)
29 dols = substr(n, 1, length(n)-3)
31 return "zero dollars and " cents " cents exactly"
32 return intowords(dols) " dollars and " cents " cents exactly"
35 function intowords(n) {
38 return intowords(n/1000) " thousand " intowords(n%1000)
40 return intowords(n/100) " hundred " intowords(n%100)
42 return tens[int(n/10)] " " intowords(n%10)
47 split("one two three four five six seven eight nine " \
48 prchecks "ten eleven twelve thirteen fourteen fifteen " \
49 prchecks "sixteen seventeen eighteen nineteen", nums, " ")
50 split("ten twenty thirty forty fifty sixty " \
51 prchecks "seventy eighty ninety", tens, " ")