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.

I have the opposite problem to this question. I want the decimal parts of an integer printed for consistency's sake. I already tried specifying the precision but without success. See below. an example

\documentclass{article}
\usepackage{pgfplots}

\begin{document}
\begin{tikzpicture}
\begin{axis}[ybar,
nodes near coords, %={\pgfmathprintnumber[fixed,precision=2]{\pgfplotspointmeta}}
]
\addplot coordinates { (1,1.11) (2,2.22)(3,3.00)(4,4.44) };
\end{axis}
\end{tikzpicture}
\end{document}

Follow up question in response to Peter Grill's answer:

Is it possible to let this specifications only affect the nodes over the bars and let the axis ticks stay without additional decimal parts? That would be the high point.

Answer: By chance I already found the answer to that one myself. Setting

\pgfkeys{
    /pgf/number format/precision=0, 
    /pgf/number format/fixed zerofill=true }

to 0 and using

nodes near coords={\pgfmathprintnumber[fixed,precision=2]{\pgfplotspointmeta}}

in the axis-specifications, I get "normal " integers on the axes and enforced decimal parts in the chart itself.

share|improve this question
    
Your title asks about pgfmath, but your example is using pgfplots, which is not the same. Please change the title accordantly if this question is directly targeted on pgfplots, not pgfmath macros in general. –  Martin Scharrer Feb 2 '12 at 16:28
    
@MartinScharrer: Of course I will change the title if it's flawed. Truth be told, my knowledge of pgfplots and pgfmath is basic at best. I encountered this problem by using pgfplots and deducted from posts such as the linked one that there must be something as pgfmath at work here. So if someone knows what the better title would be, please tell me and I'll change it accordingly. –  meep.meep Feb 3 '12 at 9:23

1 Answer 1

up vote 7 down vote accepted

You need:

/pgf/number format/precision=1, 
/pgf/number format/fixed zerofill=true

enter image description here

\documentclass{article}
\usepackage{pgfplots}

\begin{document}
\begin{tikzpicture}
\pgfkeys{
    /pgf/number format/precision=1, 
    /pgf/number format/fixed zerofill=true
}

\begin{axis}[ybar, nodes near coords]
\addplot coordinates { (1,1.11) (2,2.22)(3,3.00)(4,4.44) };
\end{axis}
\end{tikzpicture}
\end{document}
share|improve this answer
    
Thanks a lot so far. Would you happen to know the solution to my follow up question as well? –  meep.meep Feb 3 '12 at 9:33
    
Never mind that, I already solved the follow up. Thanks again! –  meep.meep Feb 3 '12 at 9:53

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.