2

I have three counters counterBoat, counterThink and counterWork.

I want to print the integer "round"(100*counterBoat/(counterBoat+ counterThink+ counterWork)) in my document.

I use the package totcount.

1
  • Load the xfp package and use \inteval, and use \value to access the values of the counters. The result is rounded by default. \inteval{100*\value{counterBoat}/(\value{counterBoat}+\value{counterThink}+\value{counterWork})} Commented Oct 2, 2019 at 12:54

1 Answer 1

5
 \numexpr(100*\value{counterBoat}) / 
        ( \value{counterBoat} + \value{counterThink} + \value{counterWork})\relax
15
  • 1
    Just +1 for not using unneeded packages... My previous comment about lost parenthesis was no valid ... was a combination of edited and non edited answer ... Sorry.
    – koleygr
    Commented Oct 2, 2019 at 12:57
  • 3
    If you want to print that number rather than use it in another calculation, prefix with \the Commented Oct 2, 2019 at 12:57
  • @koleygr your comment was valid until (literally) a second before you posted it, so no need to apologise! Commented Oct 2, 2019 at 12:58
  • 1
    @Colas as I say just put \the in front of that line in a document and the number will be printed. There is no testable code in this answer as you did not supply a test document in the question. Commented Oct 2, 2019 at 15:03
  • 1
    @Colas of course not, you are using \numexpr and counters so this is integer arithmetic. That appears to be a completely different question, perhaps you want to use the xfp package and floating point arithmetic, i really can't guess. Commented Oct 2, 2019 at 16:03

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .