3

I have this \foreach statement which results in even numbers with decimals. I would like to omit or hide the decimal from the results. How can this be done simply? I have seen a few answers to much more complicated queries, but I can find a way to marry those solutions to my question.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{snakes,backgrounds,arrows,decorations.markings}
\begin{document}
%
%
\begin{center}
\begin{tikzpicture}

\draw   [<-]    (0,7)       --      (0,3.8)
              node    [at start,left]         {$A.$};     
                \draw   [->]    (-0.2,4)    --      (3,4);
                \foreach [evaluate=\y as \yeval using \y*10] \y in {4,5,6,7}
                    \draw   (-2pt,\y)   --  (2pt,\y)
                    node    [anchor=east,left]  at (0,\y) {$\small \yeval$};


\end{tikzpicture}
\end{center}
%
%
\end{document}
3
  • 1
    You may use int(\y*10) instead of \y*10... Jun 4, 2013 at 15:40
  • 1
    I don't know tikz, but changing \y*10 to \y0 will give desired labels. But I don't know if it breaks the plot in other ways. Jun 4, 2013 at 15:40
  • 3
    I would use the PGF number parser to print the number. If you say {\small \pgfmathprintnumber{\yeval}}, the number will be automatically rounded. This macro allows you to control the number output very flexibly, without changing the calculation of the value.
    – Jake
    Jun 4, 2013 at 16:28

1 Answer 1

6

Remarks

You could make use of PGF's \pgfmathprintnumber. Review section 66 of the PGF Manual for further information. I also cleaned up the code a little.

Implementation

\documentclass{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
    \draw[<-] (0,7) node[right] {$A.$} -- (0,3.8);     
    \draw[->] (-0.2,4) -- (3,4);
    \foreach[evaluate=\y as \yeval using \y*10] \y in {4,5,6,7} {
        \draw (-2pt,\y) -- (2pt,\y) node[left] at (0,\y) {\small $\pgfmathprintnumber{\yeval}$};
    }
\end{tikzpicture}
\end{document}

Output

out

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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