[R] Strange sprintf Behavior

Jeff Newmiller jdnewmil at dcn.davis.CA.us
Wed Apr 2 16:14:40 CEST 2014


It is poor netiquette to reply to a thread with a different subject. Please start a new thread for a new subject.

As for your question, see FAQ 7.31. This is standard floating point numerical limitations at work.
---------------------------------------------------------------------------
Jeff Newmiller                        The     .....       .....  Go Live...
DCN:<jdnewmil at dcn.davis.ca.us>        Basics: ##.#.       ##.#.  Live Go...
                                      Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/Batteries            O.O#.       #.O#.  with
/Software/Embedded Controllers)               .OO#.       .OO#.  rocks...1k
--------------------------------------------------------------------------- 
Sent from my phone. Please excuse my brevity.

On April 2, 2014 4:32:26 AM PDT, Michael Smith <my.r.help at gmail.com> wrote:
>All,
>
>I'm getting this:
>
>> sprintf("%.17f", 0.8)
>[1] "0.80000000000000004"
>
>Where does the `4` at the end come from? Shouldn't it be zero at the
>end? Maybe I'm missing something.
>
>> sessionInfo()
>R version 3.0.2 (2013-09-25)
>Platform: x86_64-redhat-linux-gnu (64-bit)
>
>locale:
> [1] LC_CTYPE=en_US.utf8       LC_NUMERIC=C
>LC_TIME=en_US.utf8
> [4] LC_COLLATE=en_US.utf8     LC_MONETARY=en_US.utf8
>LC_MESSAGES=en_US.utf8
> [7] LC_PAPER=en_US.utf8       LC_NAME=C                 LC_ADDRESS=C
>
>[10] LC_TELEPHONE=C            LC_MEASUREMENT=en_US.utf8
>LC_IDENTIFICATION=C
>
>attached base packages:
>[1] stats     graphics  grDevices utils     datasets  methods   base
>
>
>Thanks,
>
>M
>
>______________________________________________
>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.




More information about the R-help mailing list