[Tex/LaTex] Best way to display percentages in Sweave

formattingsweave

What is the best way to display percentages in Sweave?

A simple example:

The number 4 is \Sexpr{4 / 7} of 7.

What is the best way to get the document to display:

The number 4 is 57.1% of 7.

Best Answer

I would use siunitx for typesetting the number with the percent sign, which will take care of the correct spacing, and do the conversion to a percentage and the rounding within the \Sexpr:

The number 4 is \SI{ \Sexpr{round(4 / 7 * 100, 1)} }{\percent} of 7.