# Reduce the number of figures presented after the decimal point in a function

I have a function to report the results of a statistical test (ANOVA) in the correct format, which I had help in doing from this post.

I now need to reduce the number of figures presented after the decimal point such that the F value (#3) is followed by 2. How can I do this without having to go through each instance I use the function and change this manually?

MWE:

    \documentclass{article}

\def\anova(#1,#2,#3,#4){$F_{#1,#2}\!=\!#3$, $p\!=\!#4$}

\begin{document}

The results are \anova (1,14,1.234,.001)

\end{document}


The end result should look like this – note that the p (#4) value does not have a 0 before the decimal point.

• I don't understand this question! The number of decimal points? Each number has a decimal point only. Do you mean the number of figures after the decimal point? – user31729 Aug 18 '16 at 17:11

Use siunitx and its \num command, with appropiate settings depending on the desired formatting (see code example)

\documentclass{article}

\usepackage{siunitx}
\def\anova(#1,#2,#3,#4){$F_{#1,#2}\!=\!\num[round-mode=places,round-precision=2]{#3}$, $p\!=\!\num[add-integer-zero=false]{#4}$}

\begin{document}

The results are \anova (1,14,1.234,.001)

\end{document}


• I have edited the question to clarify how the p value should be expressed. – George Vousden Aug 18 '16 at 17:20
• @GeorgeVousden: See the update please – user31729 Aug 18 '16 at 18:25