[R] Rounding behavior

Benoit Vaillant beno|t@v@|||@nt @end|ng |rom no-|og@org
Tue Oct 9 20:00:04 CEST 2018


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

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 866 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20181009/0b862d59/attachment-0002.sig>


More information about the R-help mailing list