How to create comma-formatted number from macro output value?

In the following document I would like for the numbers to have a thousandths separator comma.

\documentclass{article}
\usepackage{totcount}
\begin{document}

\newtotcounter{fund}

In total, my funding was \$\total{fund}. My first funding was worth \$\fund{3000}.

My second funding was worth \$\fund{50000}. \end{document}  I have tried the sistyle and siunitx packages in the Preamble, but to no avail. \usepackage{sistyle} \SIthousandsep{,}  or \usepackage[group-separator={,}]{siunitx}  How can I get a comma between these values that won't break the code? 2 Answers Solution to the Updated Question The question was updated after I posted my answer. Here is the solution to the updated one. This uses the refcount package. You need to save the total in a label whenever you wish and then use this whenever you want. \documentclass{article} \usepackage{refcount} \usepackage[group-separator={,}]{siunitx} \makeatletter \def\refcounter#1{% \protected@edef\@currentlabel {\csname p@#1\endcsname\csname the#1\endcsname}% } \makeatother \newcounter{fund} \def\fund#1{\addtocounter{fund}{#1}\$\num{#1}}
\def\SaveTotal#1#2{\refcounter{#1}\label{#2}}
\newcounter{showtotal}
\def\ShowTotal#1{\setcounterref{showtotal}{#1}\${\num{\arabic{showtotal}}}} \begin{document} After the second one, my total funding was \ShowTotal{totalOne}. And my third and fourth funding made my total funding \ShowTotal{totalTwo}. My first funding was worth \fund{3000}. My second funding was worth \fund{50000}. \SaveTotal{fund}{totalOne} Then, I got a third funding of \fund{150000}. And finally got a fourth funding of \fund{50000000}. \SaveTotal{fund}{totalTwo} \end{document}  The Updated Output Solution to the Original Question The Basics Merely using the siunitx package does not ensure (it should not) that all your numbers are automatically formatted. You need to explicitly call the \num command in order to have a number formatted. So, I modified your \fund command little, and defined the \Total command to display the counter value. (I took the liberty of putting in the$ symbol inside the macros.)

The Code

\documentclass{article}
\usepackage{totcount}

\usepackage[group-separator={,}]{siunitx}

\begin{document}

\newtotcounter{fund}
\newcommand{\fund}[1]{\addtocounter{fund}{#1}\$\num{#1}} \def\Total#1{\$\num{\arabic{#1}}}

My first funding was worth \fund{3000}.

My second funding was worth \fund{50000}.

Thus, in total, my funding was \Total{fund}.

\end{document}


The Output

\newcommand{\total}[1]{\\$\ref{tot:#1}}% Recall tot:#1 \label

\begin{document}

In total, my funding was \total{fund}.

My first funding was worth \fund{3000}.

My second funding was worth \fund{50000}.

\end{document}