[R] Rounding behavior

Ryan Derickson r|der|ck@on @end|ng |rom gm@||@com
Tue Oct 9 20:43:45 CEST 2018


I thought it might be a floating issue but didn't see the connection.
Thanks everyone.

On Tue, Oct 9, 2018, 2:00 PM Benoit Vaillant <benoit.vaillant using no-log.org>
wrote:

> Hello,
>
> On Tue, Oct 09, 2018 at 01:14:54PM -0400, Ryan Derickson wrote:
> > Apologies if this is a simple misunderstanding.
>
> See for example:
>
> https://cran.r-project.org/doc/FAQ/R-FAQ.html#Why-doesn_0027t-R-think-these-numbers-are-equal_003f
>
> > round((.575*100),0) gives 57
> > round(57.5,0) gives 58
> >
> > Why?
>
> Not R related at all.
>
> $ python
> Python 2.7.13 (default, Sep 26 2018, 18:42:22)
> [GCC 6.3.0 20170516] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
> >>> round((.575*100),0)
> 57.0
> >>> round(57.5,0)
> 58.0
>
> Same "issue". :)
>
> You'll need to dig into how numbers are floating numbers are
> represented in a finite set.
>
> Cheers,
>
> --
> Benoît Vaillant
>

	[[alternative HTML version deleted]]




More information about the R-help mailing list