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 Dimensioning of a technical drawing in TikZ a very nice solution to mark lengths on a drawing has been given that uses pgfmath's capability. How do I omit having the decimal part of the number printed, eg: 25 instead of 25.0?

share|improve this question
add comment

1 Answer

You can use the optional arguments of \pgfmathprintnumber to either cut off the decimal part or to round the number to an integer. Alternatively, you can use the \num macro from the siunitx package to round the number:

\documentclass{article}
\usepackage{tikz}
\usepackage{siunitx}
\begin{document}
\pgfmathsetmacro\testnumber{25.7}
\pgfmathprintnumber{\testnumber}

\pgfmathprintnumber[int trunc]{\testnumber}

\pgfmathprintnumber[fixed,precision=0]{\testnumber}

\num{\testnumber}

\num[round-mode=figures]{\testnumber}
\end{document}

different rounding methods

share|improve this answer
    
Yes it's the better way –  Alain Matthes Jun 1 '11 at 7:52
    
Hi Jake, Thanks for the answer, but when I cut and paste the above example into a document, pdflatex can't typeset it. It returns: Undefined control sequence. l.4 \pgfmathprintnumber –  Chah Jun 1 '11 at 9:19
    
@Chah: You might have to update to a more recent version of PGF for this. –  Andrew Stacey Jun 1 '11 at 10:21
    
@Chah: Yes, it looks like you're using an outdated version of PGF. You can get the version number by inserting \pgfversion in your document; it should be at least v2.1. –  Jake Jun 1 '11 at 10:59
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.