## LaTeX forum ⇒ General ⇒ Counters as Variables Topic is solved

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

### Counters as Variables

Hi,

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.

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

Tags:

nikolapoljak
Posts: 9
Joined: Sun Feb 26, 2012 3:03 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.
`\FPdiv\intresult{\csname thecountA\endcsname}{\csname thecountB\endcsname}\FPround\final{\intresult}{2}`

I get the final solution rounded off to two decimals. Writing it out in text is simple, something like this.
`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.

cgnieder
Site Moderator
Posts: 1951
Joined: Sat Apr 16, 2011 7:27 pm
Location: Germany
Contact:
The fp package would also have been one of my suggestions. Other possibilities for calculating real numbers are

Regards
Clemens
------------------------------