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?

  • 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. Nov 25, 2011 at 11:29

3 Answers 3


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).

  • 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, 2011 at 12:15

If you are performing simple floating point operations I think you can use pst-fp. I used it in this tex file.


It works with dot as default.

Take a look in the pst-news and search for the commands like \pstFPadd, \pstFPmul,\pstPFdiv



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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy