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 at steno.dk http://www.biostat.ku.dk/~bxc This e-mail (including any attachments) is intended for the ...{{dropped}}
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@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@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]]
A good reference is: *What Every Computer Scientist Should Know About Floating-Point* *...*<http://docs.sun.com/source/806-3568/ncg_goldberg.html> http://docs.sun.com/source/806-3568/ncg_goldberg.html On 6/11/07, BXC (Bendix Carstensen) <bxc@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@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]]