LaTeX forum ⇒ GeneralCounters as Variables Topic is solved

LaTeX specific issues not fitting into one of the other forums of this category.
Posts: 9
Joined: Sun Feb 26, 2012 3:03 pm

Counters as Variables

Postby nikolapoljak » Fri Apr 19, 2013 7:15 pm


Let's say I have two counters set up in a file that do their counting correctly. Printing out a total value of a counter is simple, but how could I print out a ratio of two totals (something like \total{counta}/\total{countb}) to a specific number of decimal points? Also, how could I print the value of a counter divided by some pre-specified number?

I've looked around to find this, but didn't have any luck.

Last edited by nikolapoljak on Sat Apr 20, 2013 9:37 pm, edited 2 times in total.

Posts: 9
Joined: Sun Feb 26, 2012 3:03 pm

Postby nikolapoljak » Sat Apr 20, 2013 9:37 pm

Solved - more or less, by using packages totcount and fp and by using \csname. Couldn't find a simpler workaround.

After filling in counters countA and countB, defined whit \newtotcount I can do this.
  1. \FPdiv\intresult{\csname thecountA\endcsname}{\csname thecountB\endcsname}
  2. \FPround\final{\intresult}{2}

I get the final solution rounded off to two decimals. Writing it out in text is simple, something like this.
  1. The result I got is \final.

Of course, if say countB gets filled after the calculation written here, run LaTeX twice so that the \totcount does it's thing.

User avatar
Site Moderator
Posts: 1948
Joined: Sat Apr 16, 2011 7:27 pm
Location: Germany

Postby cgnieder » Sun Apr 21, 2013 11:46 am

The fp package would also have been one of my suggestions. Other possibilities for calculating real numbers are

New German Q&A site about TeX:

Return to “General”

Who is online

Users browsing this forum: Baidu [Spider] and 4 guests