Did you know ... Search Documentation:
Pack number_to_word -- prolog/number_to_word.pl
PublicShow source

Small utility pack for converting integers to English words.

author
- Ebrahim Azarisooreh
license
- MIT
 number_word(?Num, ?Word) is nondet
True if Word is a (possibly) nested list of English words that represents the integer that Num is trying to represent.
Arguments:
Num- is a flat list of integer digits that correspond to the number in each place of the entire number. A whole number must be represented with a length that's a multiple of 3. For example, [0,0,3] is correct, but [3] is not.
Word- is a list of English words correspond to an integer. Every number that represents a magnitude that increases by the order of 10^3, is encased in its own list.

In example,

?- number_word([5,5,2,0,1,2,0,0,6], Word).
Word = [[five, hundred, fifty, two], million, [twelve], thousand, six]

?- number_word([0,0,6], Word).
Word = [six]

?- number_word(Number, [[one], thousand, three, hundred, seventy, two]).
Number = [0, 0, 1, 3, 7, 2]

?- number_word(Number, [[one], thousand, X, hundred, seventy, two]).
Number = [0, 0, 1, 1, 7, 2],
X = one ;
Number = [0, 0, 1, 2, 7, 2],
X = two ;
Number = [0, 0, 1, 3, 7, 2],
X = three ;
... etc.