Re: [R] rounding

From: jim holtman <jholtman_at_gmail.com>
Date: Thu, 10 Jul 2008 21:55:52 -0400

Here is what I get on a Windows with r2.71

> x <- 0.55
> 100*x - 55

[1] 7.105427e-15
> y <- 2.55
> 100*y - 255

[1] -2.842171e-14
> round(x,1)

[1] 0.6
> round(y,1)

[1] 2.5
>

On Thu, Jul 10, 2008 at 9:10 PM, Moshe Olshansky <m_olshansky_at_yahoo.com> wrote:
> Actually, your result is strange, since if x = 0.55 then a hexadecimal representation of x*100 is 404B8000 00000001 which is above 55, meaning that x is above 0.55 and should have been rounded to 0.6, while if x = 2.55 then the hexadecimal representation of x*100 is 406FDFFF FFFFFFFF which is below 255, so that x is less than 2.55 and should have been rounded to 2.5.
>
>
> --- On Fri, 11/7/08, Moshe Olshansky <m_olshansky_at_yahoo.com> wrote:
>
>> From: Moshe Olshansky <m_olshansky_at_yahoo.com>
>> Subject: Re: [R] rounding
>> To: r-help_at_stat.math.ethz.ch, "Korn, Ed (NIH/NCI) [E]" <korne_at_ctep.nci.nih.gov>
>> Received: Friday, 11 July, 2008, 10:39 AM
>> The problem is that neither 0.55 nor 2.55 are exact machine
>> numbers (the computer uses binary representation), so it
>> may happen that the machine representation of 0.55 is
>> slightly less than 0.55 while the machine representation of
>> 2.55 is slightly above 2.55.
>>
>>
>> --- On Fri, 11/7/08, Korn, Ed (NIH/NCI) [E]
>> <korne_at_ctep.nci.nih.gov> wrote:
>>
>> > From: Korn, Ed (NIH/NCI) [E]
>> <korne_at_ctep.nci.nih.gov>
>> > Subject: [R] rounding
>> > To: r-help_at_stat.math.ethz.ch
>> > Received: Friday, 11 July, 2008, 6:07 AM
>> > Hi,
>> >
>> > Round(0.55,1)=0.5
>> >
>> > Round(2.55,1)=2.6
>> >
>> > Can this be right?
>> >
>> > Thanks,
>> >
>> > Ed
>> >
>> > [[alternative HTML version deleted]]
>> >
>> > ______________________________________________
>> > 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.
>
> ______________________________________________
> 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.
>

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

What is the problem you are trying to solve?

______________________________________________
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 Fri 11 Jul 2008 - 02:04:30 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 Fri 11 Jul 2008 - 09:31:54 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