Re: [R] Rounding?

From: jim holtman <jholtman_at_gmail.com>
Date: Mon, 11 Jun 2007 07:31:21 -0400

your number 6.6500000000000001 is to large to fit in a floating point number. It takes 56 bits and there are only 54 in a real number so the system see it as 6.65 and does the rounding to an even digit; 6.6

6.650000000000001 does fit into a real number (takes 54 bits) and this will now round to 6.7

On 6/11/07, BXC (Bendix Carstensen) <bxc_at_steno.dk> wrote:
>
> I was a bit puzzed by:
>
> > formatC(6.65,format="f",digits=1)
> [1] "6.6"
>
> So I experimented and found:
>
> > formatC(6.6500000000000001,format="f",digits=1)
> [1] "6.6"
> > formatC(6.650000000000001,format="f",digits=1)
> [1] "6.7"
> > round(6.6500000000000001,1)
> [1] 6.7
> > round(6.650000000000001,1)
> [1] 6.7
> > version
> _
> platform i386-pc-mingw32
> arch i386
> os mingw32
> system i386, mingw32
> status
> major 2
> minor 5.0
> year 2007
> month 04
> day 23
> svn rev 41293
> language R
> version.string R version 2.5.0 (2007-04-23)
>
> My machine runs Windows NT.
>
> Is this intended or just a Windows facility?
> ______________________________________________
>
> Bendix Carstensen
> Senior Statistician
>
> Steno Diabetes Center
> Niels Steensens Vej 2-4
> DK-2820 Gentofte
> Denmark
> +45 44 43 87 38 (direct)
> +45 30 75 87 38 (mobile)
> +45 44 43 73 13 (fax)
> bxc@steno.dk http://www.biostat.ku.dk/~bxc
>
> This e-mail (including any attachments) is intended for the ...{{dropped}}
>
> ______________________________________________
> R-help_at_stat.math.ethz.ch 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.
>

-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem you are trying to solve?

	[[alternative HTML version deleted]]

______________________________________________
R-help_at_stat.math.ethz.ch 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 Mon 11 Jun 2007 - 11:37:14 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 Tue 12 Jun 2007 - 07:32:02 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.