Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

This is a wild one: can anyone write a code that converts a number into the corresponding word? e.g.:

4 -> 'four'
31 -> 'thirty-one'

and so on. Obviously, it is not enough to build an array in which you can store the numbers and the word associated with it and then just print instead of the number the stored word. What complicates matters more, are numbers like 11 ('eleven'). I intend to use it for numbering equations. So, anybody up to it?

share|improve this question

3 Answers 3

up vote 24 down vote accepted

You can use the fmtcount package to achieve that:

\documentclass{minimal}
\usepackage{fmtcount}

\begin{document}

4: \numberstringnum{4}

31: \numberstringnum{31}

\end{document}

Use \Numberstringnum and \NUMBERstringnum respectively for capitalized and full-caps versions.

share|improve this answer
1  
Concerning I18N: If \usepackage[ngerman]{babel} is in the document header, then the numbers are output in German. –  feklee Oct 17 '13 at 14:12

The moreenum package already does this as well.

\documentclass{article}
\usepackage{moreenum}
\newcounter{mycounter}
\renewcommand{\themycounter}{\Nthwords{mycounter}}
\begin{document}

\setcounter{mycounter}{11}
\themycounter

\setcounter{mycounter}{470}
\themycounter

\end{document}

Result:

enter image description here

Use \nthwords for lowercase. I think in the next version of the package, these will change to \nwords and \Nwords.

share|improve this answer
3  
Hmmm... CTAN has a full documentation for fmtcount. The same is not true for moreenum. Plus fmtcount has more macros. Thanks anyway for your suggestion, I really appreciate you took your time to look into it! –  Count Zero Sep 13 '11 at 15:21
    
texdoc moreenum gives me documentation; not sure why it's not showing up on CTAN. –  frabjous Sep 13 '11 at 15:56
1  
moreenum actually uses fmtcount internally. The documentation doesn't show up on that CTAN page, but if you click the CTAN directory link, you get moreenum-testcase.pdf which also serves as documentation. In fact, the package is simple enough that basically everything you need to know is in the readme anyway... –  Seamus Nov 3 '11 at 8:28
    
Oh yeah. The version of moreenum on CTAN still has \nwords and \nthwords the wrong way round! The version on github has this fixed. I will upload a new version to CTAN today. (which will also have the documentation renamed so that CTAN finds it.) –  Seamus Nov 3 '11 at 8:45

fmcount only works with numbers up to 100,000. For larger numbers, you will need to use numname which borrows the code from the memoir class. From what I recall, this can deal with bigger numbers. Neither the readme nor the package documentation actually tells you what the commands to use are, so here they are:

  • \numtoname turns a number into lowercase words (e.g. one)
  • \numtoName as above, but the first letter is capitalised
  • \NumToName as above but all words are capitalised
  • \ordinaltoname turns a number into lc ordinal (e.g. first)
  • \ordinaltoName as above but first letter capitalised
  • \OrdinalToName as above but all words capitalised

This package seems to manage all numbers up to TeX's limit of 2147483647. (numname helfully informs me that this is: two billion, one hundred and forty-seven million, four hundred and eighty-three thousand, six hundred and forty-seven)

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.