# Delete commas within numbers

To use package{calc} for calculation, number should not include any commas. So I tried to use \def\commatonone #1,#2.00 {#1#2} to get the number without commas.

\documentclass{article}
\usepackage{calc}
\def\commatonone #1,#2.00 {#1#2}

\begin{document}
\commatonone 192,150.00
\end{document}

However, if I use command to define the number, error happens.

\documentclass{article}
\usepackage{calc}
\def\commatonone #1,#2.00 {#1#2}
\newcommand{\BASESALARYAMOUNT}{149,500.00}
\newcommand{\PREVIOUSBASESALARYAMOUNT}{110,000.00}

\begin{document}

\newcounter{BASESALARYDIFFERENCE}

\end{document}
Error: Paragraph ended before \commatonone was complete. []

Are there any way to fix it? Or any better way to do the calculation with the number having commas already? (numbers are input from other files, so cannot change from raw data). And I hope it can be used for numbers like xxx.xx, xxx,xxx.xx, xxx,xxx,xxx.xx etc.

• Could you add an example of calculations you're performing? Dec 14, 2015 at 9:26
• how are the numbers input from files ? perhaps a \catcode, 9 before the \input (and \catcode44 12 after) could work, depending on the file contents. But you also have the issue of the decimal part .00 which can not be used, even with calc as is in a \addtocounter. (this is why David's answer removes it)
– user4686
Dec 14, 2015 at 18:47

This works for any number of commas and more than one level of macro expansion. It assumes that .00 is always present, making it optional would also be possible but complicate the coding a bit.

\documentclass{article}
\usepackage{calc}

\def\commatonone{\expandafter\zappointzerozero
\romannumeral\^^@}

\def\zappointzerozero#1.00{\zapcomma#1,!}
\def\zapcomma#1,#2{#1\ifx!#2\else#2\expandafter\zapcomma\fi}

\newcommand{\BASESALARYAMOUNT}{149,500.00}
\newcommand{\PREVIOUSBASESALARYAMOUNT}{110,000.00}
\newcommand{\BIGSALARYAMOUNT}{110,110,000.00}

\newcommand\extramacro{\BASESALARYAMOUNT}

\begin{document}

\newcounter{BASESALARYDIFFERENCE}

\end{document}

The following minor modification seems to work:

\documentclass{article}
\usepackage{calc}
\def\commatononei#1,#2.00{#1#2}
\def\commatonone#1{\expandafter\commatononei#1}
\newcommand{\BASESALARYAMOUNT}{149,500.00}
\newcommand{\PREVIOUSBASESALARYAMOUNT}{110,000.00}

\begin{document}

\commatonone\BASESALARYAMOUNT

\newcounter{BASESALARYDIFFERENCE}