Use evaluate option of \foreach to display integers not floats in TikZ
To get integer results, use the TikZ function int(...)
when computing \r
for the node text:
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\draw[->] (-2,0) -- (2,0) node[right] {$x$};
\draw[->] (0,-2) -- (0,2) node[above] {$y$};
\foreach \x in {-3,...,3}
\draw (\x/2,1pt) -- (\x/2,-2pt);
\foreach \y in {-3,...,3}
\draw (1pt,\y/2) -- (-2pt,\y/2);
\draw[thick,blue] (0,0) circle (1.5cm);
\foreach \x [evaluate=\x as \r using int(\x/1.5)] in {-1.5, 1.5}
\draw (\x cm,1pt) -- (\x cm,-1pt)
node[anchor=north, fill=white] {\tiny $\r$};
\end{tikzpicture}%
\end{document}
Just for completeness. In this case there is no need to evaluate anything since coordinates get parsed automatically, so you could simply do
\foreach \X in {-1, 1}
\draw (\X*1.5cm,1pt) -- (\X*1.5cm,-1pt)
node[anchor=north, fill=white,font=\tiny] {$\X$};
Please note also that \x
may not be a good loop variable if you ever intend also to make use of calc
.
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\draw[->] (-2,0) -- (2,0) node[right] {$x$};
\draw[->] (0,-2) -- (0,2) node[above] {$y$};
\foreach \X in {-3,...,3}
\draw (\X/2,1pt) -- (\X/2,-2pt);
\foreach \y in {-3,...,3}
\draw (1pt,\y/2) -- (-2pt,\y/2);
\draw[thick,blue!80!black] (0,0) circle (1.5cm);
\foreach \X in {-1, 1}
\draw (\X*1.5cm,1pt) -- (\X*1.5cm,-1pt)
node[anchor=north, fill=white,font=\tiny] {$\X$};
\end{tikzpicture}%
\end{document}