69

In most language, long numbers are split into groups of three digits, to increase readability.

In Dutch (my native language), 1000000 is usually written as 1 000 000. In English, this would be 1,000,000.

Now, I would like to know how to use this kind of formatting in LaTeX. I searched google, but I only found some articles that explain how to split very long numbers over multiple lines, which is not what I need.

Is there a package that does this automatically? Or a certain tag I can use for this?

Werner
  • 603,163
Lee White
  • 825
  • sorry I didn't realize it was latex, anyway searching "number formatting" will help you find something instead of split. for example this post: http://www.latex-community.org/forum/viewtopic.php?f=44&t=9548 hope it helps –  Apr 23 '13 at 09:45
  • 11
    siunitx provides this functionality. – Werner Apr 23 '13 at 14:20
  • 5
  • +1 for narrow space separation. I was taught in primary school in the Netherlands to use a dot, and that the Americans use a comma but that dot is european so we should use this. Later, I learned of other options like space and apostrophe which are unmistakable for a decimal separator and that just sounds like the obvious solution. – Luc Dec 01 '22 at 20:23

5 Answers5

65

You can use \, for a thin space if you are entering by hand: $1\,000\,000$

You can also use a package such as siunitx, which inserts appropriate separators and spacing automatically: \num{100000}

Which one you should use depends on what you want to do (and where the numbers are generated); whether it's a few numbers in a hand-authored text or if you are typesetting thousands of numbers in table data where hand editing to add grouping separator is not really an option.

FWDekker
  • 107
David Carlisle
  • 757,742
29

There is a good package for all of these formatting issues with numbers, either in text or in tabular: \usepackage{numprint}. Please study the manual, it provides a lot of detailed information. You get the manual usually with something like texdoc numprinton the command line.

A small MWE for numprint to answer your question:

\documentclass[english]{article}

\usepackage[T1]{fontenc} \usepackage[utf8]{inputenc} \usepackage{babel} \usepackage{numprint} \npthousandsep{,}

\begin{document}

This would be a line with a price tag: \numprint{1000000} EUR.

And as a tabular: \begin{tabular}{N{7}{0}} 1000000 {~EUR}\ \end{tabular} \end{document}

We get this:

numprint example

As you can see, just tell numprint how the thousand separator should look like. You can do much more, rounding numbers e.g.

Keks Dose
  • 30,892
4

This is very interesting exercise for TeX macro programmers. My result looks like this:

\def\num #1{\numA#1\empty\empty\empty#1\end}
\def\numA #1#2#3{%
   \ifx #1\empty \afterelax{\numB}\fi
   \ifx #2\empty \afterelax{\numB{}}\fi
   \ifx #3\empty \afterelax{\ea\numB\ignoreit}\fi
   \ea \numA \ignoreit \relax
}
\def\numB #1#2#3#4{#1#2#3\ifx#4\end\else \numseparator \ea\numB\ea#4\fi}

\def\afterelax#1#2\relax{\fi#1} \def\ignoreit#1{} \let\ea=\expandafter

\def\numseparator{,}

Test: number \num{1234567}

The \num macro is expandable.

wipet
  • 74,238
3

Well, the package SIUNITX has solved this problem easily. Try\usepackage[round-mode=places,round-precision=2,group-separator={,},output-decimal-marker={.}]{siunitx} in your preamble, and use \num{10000}. For more usages see its CTAN manual.

1

Use the package "Ziffer" which helps if you want to write 100000 as "100.000,00" it will show "10 000,00" (no space after the comma and a space instead of the dot)

gr9
  • 11
  • 12
    Please improve your answer with small. complete document, which will show syntax of using mentioned package. – Zarko Jul 24 '16 at 18:23
  • 2
    Your comment would technically apply to the accepted answer as well. – Mitja Sep 18 '17 at 18:43