I am trying to sum up entries in a table and thought using the fp package was the way to go. The MWE below,
\AddToTotal{18,000.00}
\AddToTotal{-17,000.00}
\AddToTotal{-8,000.00}
yields:
as expected. However, splitting the -8,000 into two steps breaks things:
\AddToTotal{18,000.00}
\AddToTotal{-17,000.00}
\AddToTotal{-7,000.00}
\AddToTotal{-1,000.00}% <--- Why this break things?
which should yield the same result instead produces the error:
FP error: UPN stack is empty!. \FP@errmessage #1->\errmessage {FP error: #1!}
l.25 \AddToTotal{-1,000.00} % <--- Why this break things?
Should I be using a different package for this? I only need 2 digits of precision, so perhaps there are better options.
Code:
\documentclass{article}
\usepackage{xstring}
\usepackage{siunitx}
\usepackage{fp}
\newcommand*{\Total}{0.00}% Initial Value
\newcommand*{\AddToTotal}[1]{%
\StrDel{#1}{,}[\NewAmount]%
\FPeval\TempTotal{\Total+\NewAmount}%
\xdef\Total{\TempTotal}%
%% --------
\par
After adding $\NewAmount$, total is \num[round-mode=places,round-precision=2]{\Total}.%
}%
\begin{document}
\AddToTotal{18,000.00}
\AddToTotal{-17,000.00}
\AddToTotal{-7,000.00}
\AddToTotal{-1,000.00}% <--- Why this break things?
\end{document}



xfprather thanfp. – Werner Nov 18 '18 at 03:48\xdef\Total{\fpeval{<fp>}}; it also works well with dimension calculations. – Werner Nov 18 '18 at 03:58fphas. – Peter Grill Nov 18 '18 at 04:13