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.

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.

share|improve this question
add comment

1 Answer

up vote 8 down vote accepted

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.
share|improve this answer
    
That's perfect. All the other ways I tried seemed like too much of a hack. Thank you! –  Boom Shakalaka Jan 10 '12 at 1:22
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.