lokheart lokheart - 1 year ago 57
R Question

How to make "pretty rounding"?

I need to do a rounding like this and convert it as a character:


I expect it to become
, but it just gives me

Is there anyway that I can make it show

Answer Source

Try either one of these:

> sprintf("%3.2f", round(5.9999, digits=2))
[1] "6.00
> sprintf("%3.2f", 5.999)  # no round needed either
[1] "6.00

There are also formatC() and prettyNum().

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download