[R] bug when subtracting decimals?
Dimitris Rizopoulos
d.rizopoulos at erasmusmc.nl
Mon Apr 20 15:34:40 CEST 2009
this is a (very) Frequently Asked Question; check:
http://cran.r-project.org/doc/FAQ/R-FAQ.html#Why-doesn_0027t-R-think-these-numbers-are-equal_003f
Best,
Dimitris
wolfgang.siewert wrote:
> Try this:
>
> 0.7-0.3==0.4
> (We get FALSE)
> 0.7-0.3<0.4
> (We get TRUE)
>
> but
> 0.8-0.3==0.5
> (TRUE)
> 0.8-0.3<0.5
> (FALSE)
>
> Funny, he?
>
> There is a way around:
> round(0.7-0.3,1)==0.4
> (TRUE)
>
> Obviously there is a problem with some combinations of decimal subtractions,
> that - we have the feeling - shouldt be solved.
>
> Best regards
> Sven & Wolfgang
--
Dimitris Rizopoulos
Assistant Professor
Department of Biostatistics
Erasmus University Medical Center
Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands
Tel: +31/(0)10/7043478
Fax: +31/(0)10/7043014
More information about the R-help
mailing list