10

I want to keep all useless zeros using siunitx. How could I ?

\documentclass{article}
\usepackage{siunitx}

\begin{document}

\verb+\num{5}+: \num{5}\\
\verb+\num{05.0}+: \num{05.0}\\
\verb+\num{0.5}+: \num{0.5}\\
\verb+\num{00.50}+: \num{00.50}\\

\end{document}

With the package xstring one can use :

\newcommand{\Num}[1]{%
    \StrPosition{#1}{.}[\p]%
    \num[minimum-integer-digits=\p-1]{#1}
}

1 Answer 1

13

You can use the options minimum-integer-digits

\documentclass{article}
\usepackage{siunitx}

\begin{document}
  \noindent\verb+\num{5}+: \num{5}\\
  \verb+\num{05.0}+: \num[minimum-integer-digits=2]{5.0}\\
  \verb+\num{0.5}+: \num{.5}\\
  \verb+\num{00.50}+: \num[minimum-integer-digits=2]{.50}%
\end{document}

enter image description here

Or you can use \num[parse-numbers=false]{00.50} or \sisetup{parse-numbers=false}. But then the argument of \num will not be parsed at all.

\documentclass{article}
\usepackage{siunitx}

\begin{document}

{\sisetup{parse-numbers=false}%
  \noindent\verb+\num{5}+: \num{5}\\
  \verb+\num{05.0}+: \num{05.0}\\
  \verb+\num{0.5}+: \num{0.5}\\
  \verb+\num{00.50}+: \num{00.50}%
}

\end{document}

The result is the same as above.

3
  • @egreg Of course you are right. I have changed my answer.
    – esdd
    Commented Jul 22, 2014 at 11:19
  • 4
    You only really need minimum-integer-digits here: the rounding stuff can happily be omitted.
    – Joseph Wright
    Commented Jul 22, 2014 at 11:20
  • @JosephWright Thank you for the note. I have edited my answer again.
    – esdd
    Commented Jul 22, 2014 at 11:27

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .