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