3

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.

Mark Karpov
  • 7,499
  • 2
  • 27
  • 62
  • 1
    Any chance this is what you are looking for? https://github.com/andersjanmyr/roman-numerals-kata – allen1 Aug 26 '14 at 14:43
  • @Dan, yes, I like it! Although the library doesn't help with first part of my question... – Mark Karpov Aug 26 '14 at 14:45
  • Hmm, this thread has some code that does this posted: http://stackoverflow.com/questions/14766951/convert-digits-into-words-with-javascript – allen1 Aug 26 '14 at 14:48
  • Thanks! If there is no library for this, I'll write it from scratch anyway (functionally and elegant) ;-) – Mark Karpov Aug 26 '14 at 14:51

1 Answers1

6

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.
edbond
  • 3,921
  • 19
  • 26
  • 1
    Huh! What a thing! I'm a Common Lisper for three years and now this mega-function is with me in Clojure! Yippee! – Mark Karpov Aug 26 '14 at 16:30