lokheart lokheart - 2 months ago 7
R Question

Rounding numbers in R


Possible Duplicate:

how to make “pretty rounding” in R?




I have a number, say
1.036315
, which I want to round it to the firsts decimal place, so that the outcome is
1.0
, which should not be
1
, as I also want to state that the approximation is accurate to the first decimal place.

But when I use
round(1.036315, digits=1)
, R gives me
1
, which is something I don't want.

Any way for making R to present the thing I want?

Answer
sprintf("%.1f",1.036315)

should do the trick.

Comments