1

I would like to format large numbers like 31556952000 with a thousands separator as 31,556,952,000. Adding \usepackage[group-separator={,}]{siunitx} in the preamble and \num{31556952000} in the body has worked quite well, but is not suitable for ACM TAPS submission as siunitx is not on the approved list of packages. As Preserving thousands separator with siunitx, this is an imposed requirement.

How may I get comma-separated thousands using only packages supported by ACM TAPS?

1 Answer 1

2

Taking the core loop from siunitx and writing out, we'd get something like

\documentclass{article}
\makeatletter
\providecommand*\num[2][]{%
  \ensuremath{%
    \num@auxi{0}{}#2\num@q@stop
  }%
}
\newcommand\num@auxi{}
\long\def\num@auxi#1#2#3{%
  \ifx#3\num@q@stop
    \expandafter\num@auxiii
  \else
    \expandafter\num@auxii
  \fi
    {#1}{#2}{#3}%
}
\newcommand\num@auxiii[3]{%
  \expandafter\num@auxiv\expandafter
    {\number\numexpr#1\relax}{#2}%
}
\newcommand\num@auxii[3]{\num@auxi{#1 + 1}{#2#3}}
\newcommand\num@auxiv[2]{%
  \@nameuse{num@aux@\number\numexpr#1-(\@num@div#1;3;)*3\relax}{#2}%
}
\long\@namedef{num@aux@0}#1{%
  \num@loop@first#1\num@q@stop
}
\long\@namedef{num@aux@1}#1{%
  \num@loop@first{}{}#1\num@q@stop
}
\long\@namedef{num@aux@2}#1{%
  \num@loop@first{}#1\num@q@stop
}
\newcommand\num@loop@first[4]{%
  #1#2#3%
  \ifx#4\num@q@stop
    \expandafter\@gobble
  \else
    \expandafter\num@loop
  \fi
    #4%
}
\newcommand\num@loop[4]{%
  \mathord{,}%
  #1#2#3%
  \ifx#4\num@q@stop
    \expandafter\@gobble
  \else
    \expandafter\num@loop
  \fi
    #4%
}
\newcommand\@num@div{}
\long\def\@num@div#1#2;#3#4;{%
 \ifx0#1%
   0%
 \else
   (#1#2\ifx-#1+\else-\fi(\ifx-#3-\fi#3#4-1)/2)%
 \fi /#3#4%
}
\def\nume@q@stop{\nume@q@stop}
\makeatother
\begin{document}

\num{31556952000}

\end{document}
1
  • Thank you. Dumped that in lib/num.tex then added \input{lib/num} to the preamble.
    – Iiridayn
    Commented Dec 8, 2022 at 1:16

You must log in to answer this question.

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