# Convert an integer into words

### From CodeCodex

The following code will turn integer numerals (eg. 1, 2, 3) into spelled out, words (eg. "one", "two", "three").

## Implementations

### Algol 68

PROC number words = ( INT n ) STRING : # returns a string representation of n in words. Currently deals with anything from 0 to 999 999 999. # BEGIN [] STRING digits = ( "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine" ); [] STRING teens = ( "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen" ); [] STRING decades = ( "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety" ); PROC three digits = ( INT n ) STRING : # does the conversion for n from 0 to 999. # BEGIN INT tens = n MOD 100 OVER 10; INT units = n MOD 10; IF n >= 100 THEN digits[n OVER 100 + 1] + " " + "hundred" + IF n MOD 100 /= 0 THEN " and " ELSE "" FI ELSE "" FI + IF tens /= 0 THEN IF tens = 1 THEN teens[units + 1] ELSE decades[tens - 1] + IF units /= 0 THEN "-" ELSE "" FI FI FI + IF units /= 0 AND tens /= 1 OR n = 0 THEN digits[units + 1] ELSE "" FI END; INT n3 = n OVER 1 000 000; INT n2 = n MOD 1 000 000 OVER 1000; INT n1 = n MOD 1000; IF n3 /= 0 THEN three digits(n3) + " million" ELSE "" FI + IF n3 /= 0 AND (n2 /= 0 OR n1 >= 100) THEN ", " ELSE "" FI + IF n2 /= 0 THEN three digits(n2) + " thousand" ELSE "" FI + IF (n3 /= 0 OR n2 /= 0) AND n1 > 0 AND n1 < 100 THEN " and " ELIF n2 /= 0 AND n1 /= 0 THEN ", " ELSE "" FI + IF n1 /= 0 OR n = 0 THEN three digits(n1) ELSE "" FI END; DO INT n; print("n? "); read((n, new line)); print((number words(n), new line)) OD