Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

In a Tikz Figure, I'm doing some computation and want to print results as label of nodes. The problem is that I only need the integer part of the number to print.

I tried with round() function. It round the values correctly but they are printed with .0

\begin{tikzpicture}
   \foreach \i in {1,2,3,4,5,6} {
      \pgfmathparse{round(\i*100/3) }
       \let\theIntINeed\pgfmathresult
       \draw (\i,0) node {\theIntINeed};
   }
 \end{tikzpicture}
 % Results: 33.0 67.0 100.0 133.0 167.0 200.0

Thank you in advance.

share|improve this question
add comment

3 Answers

up vote 12 down vote accepted

\pgfmathparse always saves its result with a decimal part. You can either use \pgfmathprintnumber{\pgfmathresult} in the node text to output the number, which will remove the .0 for integers, or do the calculation using \pgfmathtruncatemacro\mymacro{round(\i*100/3)}, which will save the result of the calculation without the decimal part, and then use \mymacro in the node text.

share|improve this answer
add comment

You could also use the int function, which returns the integer part of the value, i.e.

\pgfmathparse{int(round(\i*100/3))}
share|improve this answer
add comment

Simply use \pgfmathtruncatemacro\theIntINeed instead of \pgfmathresult.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.