How to display numbers using comma as a thousands separator?
I think the siunitx
package has this sort of facility.
\num[group-separator={,}]{1234567890}
Should give you 1,234,567,890
Also you can use this as a package option like so: \usepackage[group-separator={,}]{siunitx}
Be warned, this doesn't seem to work with older versions of siunitx
Seamus' answer involving siunitx
is the Right WayTM to do this. That said, it's not so hard to write a simple macro to pretty-print numbers.
\newcount\ppnum
\newcommand\ppnumber[1]{%
\ppnum=#1\relax
\ifnum\ppnum<0
$-$%
\ppnum=-\ppnum
\fi
\let\pptemp\empty
\loop\ifnum\ppnum>999
\count255=\ppnum
\divide\ppnum by1000
\count255=\numexpr \count255 - 1000*\ppnum \relax
\edef\pptemp{,\ifnum\count255<100 0\ifnum\count255<10 0\fi\fi
\the\count255 \pptemp}%
\repeat
\the\ppnum
\pptemp
}
The first time I wrote this, I used a token register rather than \pptemp
, but that required writing \expandafter\expandafter\expandafter{\expandafter...
which just seemed excessive.
Edit:
Given that I've now had to fix two bugs in my code, maybe I shouldn't have claimed that it isn't so hard to do this. =)
Using the http://www.ctan.org/pkg/numprint package with \npthousandsep{,}
might be an alternative (found after writing the other answer - Murphy's Law!).
Btw: Grouping numbers into pairs of two can be done with the http://www.ctan.org/pkg/telprint package.