LaTeX error "Invalid number '1,250,000'": cause and fix
siunitx reads the first argument of \num and \qty character by character as a number, and this one does not follow the rules. Allowed are digits, a sign, one decimal marker (a period or a comma), an exponent written with e, and \pm for an uncertainty.
Why it happens
- The number has thousands separators, as in
1,250,000or1.000,5.siunitxreads both the comma and the period as decimal marker, and a number can have only one. - A power of ten is written as
10^3. - The argument holds text or the unit:
\num{2x},\qty{5m}{\second},\qty{about 5}{\metre}. - A range is written with a hyphen, as in
\qty{5-10}{\metre}. - The argument contains a macro or math mode, for example
\num{\pi}or\num{$5$}.
How to fix it
- Type the digits without separators:
\num{1250000}.siunitxgroups them in threes itself;group-separator={,}changes the separator from a thin space to a comma. - Write exponents with
e:\num{1.5e3}prints 1.5 × 10³, and\num{e3}prints 10³. - Use
\numrange{5}{10}or\qtyrange{5}{10}{\metre}for ranges. - Keep words outside the command:
about \qty{5}{\metre}. - To print the argument as it is, switch the check off:
\num[parse-numbers=false]{...}.
A document that produces the message
\documentclass{article}
\usepackage{siunitx}
\begin{document}
The city has \num{1,250,000} inhabitants.
\end{document}The corrected document
\documentclass{article}
\usepackage{siunitx}
\begin{document}
The city has \num{1250000} inhabitants.
\end{document}Both documents were compiled with pdfLaTeX from TeX Live 2023. The first produces the message, the second compiles without an error.
Finding the line in the editor
The editor lists every error and warning of a compile run with file and line. Select an entry and the cursor jumps to that line. See Error list with jump to the line.