Text Formattingnumber formatting

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Post Reply
mina
Posts: 12
Joined: Sun Jul 12, 2009 4:48 pm

number formatting

Post by mina »

Hi all,

I have been googling this but couldn't find anything.

Is there a way to make LaTeX take care of formatting numbers? For example, if I write 165010621 in my tex file I'd like to see 165,010,621 in my PDF. It's not really a big deal, I can add the commas manually, but I am really curious whether something exists to do it automatically.

I use report class and PDFLaTeX.

Cheers,
Mina
Last edited by mina on Mon Jul 26, 2010 10:07 am, edited 1 time in total.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

User avatar
Stefan Kottwitz
Site Admin
Posts: 10320
Joined: Mon Mar 10, 2008 9:44 pm

number formatting

Post by Stefan Kottwitz »

Hi Mina,

you could use the numprint package.

Stefan
LaTeX.org admin
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

number formatting

Post by localghost »

The siunitx package is also a candidate.


Thorsten
mina
Posts: 12
Joined: Sun Jul 12, 2009 4:48 pm

number formatting

Post by mina »

Hi,

Thank you guys. I tried the numprint packages. An example:

Code: Select all

\documentclass[a4paper,10pt]{report}
\usepackage[english]{babel}
\usepackage{numprint}
\begin{document}
\numprint[m^2]{48524378} (\numprint{4.8e-7}, or \numprint[mln]{48.5}) and \numprint[\%]{36.19}. 
\selectlanguage{english}
\numprint[nt]{48524378} (\numprint{4.8e7}, or \numprint[mln]{48.5}) and \numprint[\%]{36.19}.
\npdecimalsign{\ensuremath{\cdot}}
\npthousandsep{,}
\npproductsign{*}
\numprint[nt]{48524378} (\numprint{4.8e7}, or \numprint[mln]{48.5}) and \numprint[\%]{36.19}.
\end{document}
Note that the numbers are in German by default, unless you specify another language using the Babel package and the \selectlanguage command (supports English, German, Portuguese, Dutch and French) or use the autolanguage option. See manual.

Cheers,
Mina
Post Reply