Re: [R] round number

From: Duncan Murdoch <murdoch.duncan_at_gmail.com>
Date: Sat, 26 Mar 2011 16:34:52 -0400

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.



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. Received on Sat 26 Mar 2011 - 20:37:03 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sat 26 Mar 2011 - 20:40:25 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive