GeneralCounters as Variables

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

Counters as Variables

Post by nikolapoljak »

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.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

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

Counters as Variables

Post by nikolapoljak »

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.

Code: Select all

\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.

Code: Select all

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
cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

Counters as Variables

Post by cgnieder »

The fp package would also have been one of my suggestions. Other possibilities for calculating real numbers are
  • the calculator package
  • the pgf package
  • the l3fp module of the l3kernel
Regards
site moderator & package author
Post Reply