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.

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}
}
share|improve this question

1 Answer 1

up vote 13 down vote accepted

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.

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

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.