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.

  • \real does not provide integer numbers, apparently, which are desperately needed by counter registers – user31729 Apr 20 '16 at 20:46
  • @ChristianHupfer but this is how they instruct me to do it, see 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 – user31729 Apr 20 '16 at 20:49
  • Perhaps a LaTeX 3 method is more appropiate here! – user31729 Apr 20 '16 at 21:01
  • See my answer to this question for example: tex.stackexchange.com/questions/196373/… – user31729 Apr 20 '16 at 21:05
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?

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.