[R] round number

Duncan Murdoch murdoch.duncan at gmail.com
Sat Mar 26 21:34:52 CET 2011


On 11-03-26 2:05 PM, Alfredo Alessandrini wrote:
> Hi,
>
>> a<- 4
>
>> a*0.2
> [1] 0.8
>
> ok!!
>
> Is there a method to obtain this:
>
>> a*0.2
> [1] 0.80

It is easy to print values with trailing zeros, but I think it's hard to 
make it the default.  The sprintf() function is the one I'd use for the 
formatting:

sprintf("%.2f", a*0.2)

(or put noquote() around it if you don't like the quoted result).

Duncan Murdoch

>
> I need to round the number also with the zero.
>
>
>
> Thanks in advance,
>
> Alfredo
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list