[Tex/LaTex] Remove leading 0 in siunitx

siunitx

I am trying to create a big table without leading zeros using siunitx \num{}. Namely, I have a bunch of number formated like this:

0.001
0.1
1.000

and I want to remove the 0. part. So the output would be:

.001
.1
1.000

It should be the opposite of add-integer-zero option (something like remove-integer-zero). I have triyed lots of \sisetup configuration without luck. All question in tex exchange seems to be the opposite to what I want. Any idea of it is possible?

Thanks in advance.

Best Answer

I agree with the comments about this not being a good idea. But having said that, here's an approach, using the expl3 syntax that siunitx is built upon:

\documentclass{article}
\usepackage{siunitx}
\ExplSyntaxOn

\NewDocumentCommand\trimleadingzero{m}{%%
  \fp_compare:nTF { 0 < \fp_abs:n { #1 } < 1 }
    { 
      \__trimleadingzero:n {#1}
    }
    { #1 }
}

\cs_new_protected:Npn \__trimleadingzero:n #1 {
  \seq_set_split:Nnn \l_ae_integer_decimal_parts_seq {.} {#1}
  \fp_compare:nF {#1>0}
    { - }
  .\seq_item:Nn \l_ae_integer_decimal_parts_seq {2}
}

\ExplSyntaxOff
\begin{document}

\SI[add-integer-zero=false,parse-numbers=false]{\trimleadingzero{0.03}}{}

\SI[add-integer-zero=false,parse-numbers=false]{\trimleadingzero{-0.03}}{}

\end{document}

enter image description here