[Tex/LaTex] Preserving thousands separator with siunitx

siunitx

I'm writing a paper and my advisor is requiring that all large numbers have a comma as a thousands separator. I've read this question which asks about how to make siunitx not throw errors when there is a comma in the input, but how can I force a comma in the output when using \SI?

Ideally it would only do it for numbers with more than 4 digits — ie. \SI{9000} would not contain a space or comma but \SI{10000} would be 10,000. But if that's not possible, I'd settle for 9,000 also.

Best Answer

This is described in section 5.6 Printing numbers of the manual (for v. 2.5s, dated 2013/07/31). The group-separator key defines the separator between groups of digits. By default grouping is not applied for numbers with four digits (e.g. 9000), so there's no need to do anything for that. (This can be changed with group-minimum-digits, which defines how many digits must be present for grouping to apply.)

enter image description here

\documentclass[12pt]{article}
\usepackage{siunitx}
\sisetup{group-separator = {,}}
\begin{document}
\SI{9000}{\m}

\SI{90000}{\m}

\end{document}