1

I have been having troubles with the following issue:

I am making an invoice template in LaTeX. I use \addtocounter to calculate values like subtotal, tax and total. This works fine, until the value contains a decimal number (which happens often in invoices of course). To counter this, I use the calc package in order to do: \addtocounter{subtotal}{\real{19.95}}. This works fine too.

However, when I load the package numprint or siunitx so that my numbers are correctly formatted on the decimal in the invoice table, I get the error:

/Invoices/A4.tex:22 Missing number, treated as zero \addtocounter{subtotal}{\real{19.95}}

As soon as I remove those two packages, all works fine again.

My question: is there a way to format numbers in a table while still being able to calculate the totals using decimal numbers?

You can find the code here: https://www.overleaf.com/4958478dccytf#/15308055/ Note that the code includes an invoice.cls and that an example of the problem can be found in the main page on line 22 and 23.

Diederik
  • 171
  • \real does not provide integer numbers, apparently, which are desperately needed by counter registers –  Apr 20 '16 at 20:46
  • @ChristianHupfer but this is how they instruct me to do it, see http://tug.ctan.org/macros/latex/required/tools/calc.pdf (page 3). – Diederik Apr 20 '16 at 20:47
  • Well, apparently the truncating doesn't work any longer then –  Apr 20 '16 at 20:49
  • Perhaps a LaTeX 3 method is more appropiate here! –  Apr 20 '16 at 21:01
  • See my answer to this question for example: http://tex.stackexchange.com/questions/196373/is-there-a-counter-or-variable-that-can-be-used-to-store-numbers-with-decimals –  Apr 20 '16 at 21:05
  • @ChristianHupfer Thanks for the help. I have added your suggestion (see: https://www.overleaf.com/4958478dccytf#/15308070/) but as you can see the total does not add up correctly. Any insights? Thanks for the help btw! – Diederik Apr 20 '16 at 22:19
  • Not yet -- I will try to come back to it (later on) –  Apr 20 '16 at 22:23

1 Answers1

1

The \real macro seems to need arithmetics desperately, i.e. use 1*\real{19.95} etc.

But it will be truncated anyway!

\documentclass{article}

\usepackage{siunitx}
\usepackage{numprint}
\usepackage{calc}


\newcounter{foo}
\begin{document}

\addtocounter{foo}{5*\real{1.7}}

\thefoo

\end{document}

Related: Is there a counter or variable that can be used to store non-integers?