Undesired decimal

View: New views
3 Messages — Rating Filter:   Alert me  

Undesired decimal

by Hugues Vermeiren :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi, pgf-users

The Pi points in this example show an unelegant decimal.
How can I get rid of it?

\documentclass{minimal}
\usepackage{tikz}

\begin{document}
 \begin{tikzpicture}
  \foreach \i in {-4,-3,...,4}{
   \pgfmathparse{\i+5}
   \let\index\pgfmathresult
   \fill (\i,0) circle (0.5mm) node[above]{$P_{\index}$};
   };
 \end{tikzpicture}
\end{document}

Of course, the code

 \begin{tikzpicture}
  \foreach \i in {1,2,...,9}
   \fill ({\i-5},0) circle (0.5mm) node[above]{$P_{\i}$};
 \end{tikzpicture}

would do. But the question of the decimal in the first example would remain
unsolved...

More generally, how can we, pgf-users, format numbers?

Thank you,
Hugues Vermeiren



------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
pgf-users mailing list
pgf-users@...
https://lists.sourceforge.net/lists/listinfo/pgf-users

Re: Undesired decimal

by André Valentin-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Le 13 sept. 2009 à 10:41, Hugues Vermeiren a écrit :

>
> Hi, pgf-users
>
> The Pi points in this example show an unelegant decimal.
> How can I get rid of it?
>
> \documentclass{minimal}
> \usepackage{tikz}
>
> \begin{document}
> \begin{tikzpicture}
>  \foreach \i in {-4,-3,...,4}{
>   \pgfmathparse{\i+5}
>   \let\index\pgfmathresult
>   \fill (\i,0) circle (0.5mm) node[above]{$P_{\index}$};
>   };
> \end{tikzpicture}
> \end{document}
>
> Of course, the code
>
> \begin{tikzpicture}
>  \foreach \i in {1,2,...,9}
>   \fill ({\i-5},0) circle (0.5mm) node[above]{$P_{\i}$};
> \end{tikzpicture}
>
> would do. But the question of the decimal in the first example would  
> remain
> unsolved...
>
> More generally, how can we, pgf-users, format numbers?
>
> Thank you,
> Hugues Vermeiren

One possible solution :

\documentclass{minimal}
\usepackage{tikz}

\begin{document}
\newcount\index
\begin{tikzpicture}
  \foreach \i in {-4,-3,...,4}{
   \pgfmathparse{\i+5}
   \index=\pgfmathresult
   \fill (\i,0) circle (0.5mm) node[above]{$P_{\the\index}$};
   };
\end{tikzpicture}
\end{document}

HTH

André


------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
pgf-users mailing list
pgf-users@...
https://lists.sourceforge.net/lists/listinfo/pgf-users

Re: Undesired decimal

by Christophe Jorssen-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hugues Vermeiren a écrit :
> Hi, pgf-users
>
> The Pi points in this example show an unelegant decimal.
> How can I get rid of it?
>

[snip]

> More generally, how can we, pgf-users, format numbers?

See "Number Printing" and particularly options
int detect or int trunc, page 540 of the current cvs documentation.

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
pgf-users mailing list
pgf-users@...
https://lists.sourceforge.net/lists/listinfo/pgf-users