Featured Book

LaTeX Beginners Guide

Who is online

In total there are 11 users online :: 1 registered, 0 hidden and 10 guests (based on users active over the past 5 minutes)
Most users ever online was 1327 on Tue Nov 05, 2013 7:11 pm

Users browsing this forum: Majestic-12 [Bot] and 10 guests

Partner Sites

TeXwelt - Fragen und Antworten goLaTeX
TeXblog
TeXnicCenter
TeXample

Counters as Variables Topic is solved

countersprogrammingAdd tags LaTeX specific issues not fitting into one of the other forums of this category.

Counters as Variables

Postby nikolapoljak on Fri Apr 19th, 2013

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 20th, 2013, edited 2 times in total.
nikolapoljak
 
Posts: 9
Joined: Sun Feb 26th, 2012

Re: Counters as Variables  Topic is solved

Postby nikolapoljak on Sat Apr 20th, 2013

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  •  Open in writeLaTeX
\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  •  Open in writeLaTeX
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.
nikolapoljak
 
Posts: 9
Joined: Sun Feb 26th, 2012

Re: Counters as Variables

Postby cgnieder on Sun Apr 21st, 2013

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

Regards
Clemens
------------------------------
New German Q&A site about TeX: http://texwelt.de/wissen
System: TeXlive 2013, OpenSUSE 12.3
User avatar
cgnieder
Site Moderator
 
Posts: 1696
Joined: Sat Apr 16th, 2011
Location: Germany


Topic Tags

countersprogramming

Return to General

Who is online

Users browsing this forum: Majestic-12 [Bot] and 10 guests