I need to do a rounding like this and convert it as a character:
as.character(round(5.9999,2))
I expect it to become 6.00
, but it just gives me 6
Is there anyway that I can make it show 6.00
?
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()
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With