TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

After long I was exposed to TeX and to a problem that seems to be so simple in traditional languages but surprisingly hard to solve in TeX.

We have system out of our scope of control that provides us with numeric inputs to TeX in the common US format, that is dot separator for fractional part and commas separating thousands. We'd like to do basic transformations using fp package but it doesn't really support this input. Also, using \numprint doesn't seem to be working for us.

Is there any easy way how we can strip comma thousand separators off the numbers in TeX before passing it to fp for further calculations? It's easy to transform the numbers back using numprint afterwards.

We could remove one comma but is there an easy way to remove them all?

share|improve this question

migrated from stackoverflow.com Nov 25 '11 at 7:43

This question came from our site for professional and enthusiast programmers.

Welcome to TeX.sx! Your question was migrated here from Stack Overflow. Please register on this site, too, and make sure that both accounts are associated with each other, otherwise you won't be able to comment on or accept answers or edit your question. – Torbjørn T. Nov 25 '11 at 11:29

To remove all , from a string, you can use the following


% example:
\typeout{\MyFloatingPoint} % prints "1000000.00" in the log

Another solution is to use the expl3 package.

\tl_remove_all:Nn \MyFloatingPoint { , }
\typeout{\MyFloatingPoint} % prints "1000000.00" in the log

Here \ExplSyntaxOn and \ExplSyntaxOff are analogs of \makeatletter and \makeatother, which make _ and : into letters, and tell TeX to ignore spaces. The expl3 package also provides ways to manipulate floating point numbers, that could be an alternative to fp.

Also, you may be interested in using siunitx rather than numprint. It is somewhat more powerful (never used either of them, though).

share|improve this answer
As siunitx is designed for displaying numbers, it probably is not such a good choice here as the macros are not expandable. – Joseph Wright Nov 25 '11 at 12:15

You can open the TeX file in Vim and type the following:


This will find and replace any commas you have with nothing, thereby deleting them. The g at the end means "global", so if there are any commas you want left in, use cg instead of g to check before each comma.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.