Re: [R] rounding format

From: Prof Brian Ripley <ripley_at_stats.ox.ac.uk>
Date: Wed, 2 Jan 2008 19:07:15 +0000 (GMT)

On Wed, 2 Jan 2008, jim holtman wrote:

>> sprintf("%.4f", 0.0002234)
> [1] "0.0002"

Or, literally for printing, use options(scipen=). Note that round(0.0002234,4) does return (a representable number very close to) 0.0002, but it is printed by default as 2e-04.

> round(0.0002234,4)
[1] 2e-04
> options(scipen=4)
> round(0.0002234,4)
[1] 0.0002

>
>
> On Jan 2, 2008 1:45 PM, array chip <arrayprofile@yahoo.com> wrote:
>> Hi,
>>
>> The code round(0.0002234,4) will return 2e-04, how can
>> I return 0.0002 instead? I want to print 0.0002
>> instead of 2e-04 for formating purpose.
>>
>> thanks
>>
>>
>> ____________________________________________________________________________________
>> Looking for last minute shopping deals?
>>
>> ______________________________________________
>> 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.
>>
>
>
>
>

-- 
Brian D. Ripley,                  ripley_at_stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

______________________________________________
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 Wed 02 Jan 2008 - 19:11:46 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 Wed 02 Jan 2008 - 19:30:05 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