# Change number to word

Referring to the question below Set counter in exam class to a count based on the first set of questions

I would like to change the answer for this. There are \total{s}\ short questions.

From There are 2 short questions to There are TWO short questions.

Thanks.

The package fmtcount defines the command \numberstring{counter}. Adding this to the answer in Set counter in exam class to a count based on the first set of questions, we get

\documentclass{exam}

\usepackage{totcount}
\usepackage{fmtcount}
\makeatletter
\newcommand{\extractcntrvalue}[1]{%
\value{#1@totc}%
}
\makeatother

\newtotcounter{s}
\setcounter{s}{0}
\newtotcounter{e}
\setcounter{e}{0}
\newcommand{\squestion}[0]{\stepcounter{s}\question}
\newcommand{\equestion}[0]{\stepcounter{e}\question}

\begin{document}
\fullwidth{\Large \textbf{Short questions}}
There are \total{s}\ short questions. %display the number of short questions.

\begin{questions}
\squestion
This is the first short question.
\squestion
This is the second short question.
\end{questions}

\fullwidth{\Large \textbf{Essay questions}}
There are \total{e}\ essay questions. %display the number of essay questions.

\begin{questions}
\equestion
This is the first essay question.
\equestion
This is the second essay question.
\equestion
This is the third essay question.
\equestion
This is the fourth essay question.
\end{questions}

For the record there is a total of \numberstring{question} questions.

\end{document}


Note that if you want to extract the information from a "total" counter, this will not work, because totcount counters are not counters in the LaTeX sense.

However, we can use the command \extractcntrvalue defined above together with \numeberstringnum command:

\documentclass{exam}

\usepackage{totcount}
\usepackage{fmtcount}
\makeatletter
\newcommand{\extractcntrvalue}[1]{%
\value{#1@totc}%
}

\makeatother

\newtotcounter{s}
\setcounter{s}{0}
\newtotcounter{e}
\setcounter{e}{0}
\newcommand{\squestion}[0]{\stepcounter{s}\question}
\newcommand{\equestion}[0]{\stepcounter{e}\question}

\begin{document}
\fullwidth{\Large \textbf{Short questions}}
There are \numberstringnum{\extractcntrvalue{s}} short questions. %display the number of short questions.

\begin{questions}
\squestion
This is the first short question.
\squestion
This is the second short question.
\end{questions}

\fullwidth{\Large \textbf{Essay questions}}
There are \numberstringnum{\extractcntrvalue{e}} essay questions. %display the number of essay questions.

\begin{questions}
\equestion
This is the first essay question.
\equestion
This is the second essay question.
\equestion
This is the third essay question.
\equestion
This is the fourth essay question.
\end{questions}

For the record there is a total of \numberstring{question} questions.

\end{document}


• thank you, but why I can't use \value{s} alone with out \extractcntrvalue{s} Mar 20 '17 at 4:12
• I think it is discussed in the linked question Mar 20 '17 at 4:19