[R] Re: trailing zeroes

Martin Maechler maechler at stat.math.ethz.ch
Sun Feb 28 01:07:14 CET 1999


>>>>> "BDR" == Prof Brian Ripley <ripley at stats.ox.ac.uk> writes:

    >> Date: Fri, 26 Feb 1999 09:59:39 +0000 From: Bendix Carstensen
    >> <bxc at svs.dk>

    >> When you require 2 digits you expect to find 5.96 printed

    BDR> Correction, _you_ expect!  Very few computer programs do that.
    BDR> You cannot `require' two digits by options(digits=2): ?options
    BDR> says

    BDR>   digits: controls the number of digits to print when print- ing
    BDR> numeric values. It is a suggestion only.

    >> as 6.0, i.e. a number somewhere between 5.95 and 6.04999999999999.
    >> This is apparently not always the case for R.  Why does 0 have a
    >> special status as trailing digit?
    >> 
    >> > options(digits=2) > x <- c(59.6,59.4) > x [1] 60 59 > x/10 [1] 6.0
    >> 5.9 > x[1]/10 [1] 6

    BDR> Because that is how the ASCII C printing functions work.
    BDR> Ultimately print() calls sprintf with a %x.yf format. What happens
    BDR> depends on how that is implemented on your system.

    BDR> S-PLUS has an option nsmall to format to do precisely this, and
    BDR> there was a question asking how to do it on s-news today.  I have
    BDR> thought for a while that we need to implement something like this
    BDR> in R: maybe I had better do it....

Is it necessary?

In R, we've always been having   formatC(.) as an alternative to format(.)
allowing more precise formatting specifications.
However, maybe I didn't understand what yuo were alluding to..

Martin
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list