Search code examples
stringclojureintegerroman-numerals

Converting integers into words and roman numerals


Is there a library to convert integers into strings, so that they (integers) will be represented as words? For example:

21 => "twenty one"

I'm also interested in converting integers into strings that represent them as Roman numerals:

21 => "XXI"

It's not a problem for me to write such converting functions, but I don't want to reinvent the wheel.


Solution

  • Take a look at cl-format, it can return "twenty one", I used that for project euler.

    http://clojuredocs.org/clojure_core/1.2.0/clojure.pprint/cl-format

    and Roman too:

    ~@R prints arg as a Roman numeral: IV; and ~:@R prints arg as an old Roman numeral: IIII.