[Tex/LaTex] Replace . (period) by , (comma) in numbers

formattingmacros

I pass a bunch of numbers into a custom command defined via \newcommand{\mycmd}[1]{...}:

\mycmd{1.12}
\mycmd{5.32}

\mycmd uses the number to draw a certain figure. On top of that, I would like to print the number in \mycmd, but with a comma instead of a decimal point: 1,12, 5,32.

Any suggestion would be appreciated.

Best Answer

I'm sure the siunitx package is the way to go because it will catch all corner cases. Out of curiosity, here is a simple solution that uses TeX's pattern matching capabilities.

\documentclass{minimal}
\def\usecomma#1.#2{#1,#2}
\newcommand\mycmd[1]{\usecomma #1}
\begin{document}
    \obeylines
    1.12 $\to$ \mycmd{1.12}
    5.32 $\to$ \mycmd{5.32}
\end{document}

Note that it won't work if you pass an argument that has no dot, like \mycmd{2}. Is this too simple and there is something else that I have overlooked?

Related Question