# How can I print a length in centimeters? [duplicate]

(I am a new to LaTeX.) I'm trying to print a length in centimeters. Here is my code:

\documentclass{article}
\begin{document}
\newdimen\mylength
\mylength=1in
\the\mylength
\end{document}


And here is the resulting output:

72.27 pt

However, I want to show output in centimeters: Example: \the dimen [cm]\mylength. How can I do that?

You can use the \convertto macro from Philippe Goutet's post:

\documentclass{article}

\makeatletter
\def\convertto#1#2{\strip@pt\dimexpr #2*65536/\number\dimexpr 1#1}
\makeatother

\begin{document}
\newdimen\mylength
\mylength=1in
\convertto{cm}{\the\mylength} cm
\end{document}


Output:

2.54cm