[R] weird behavior of nsmall in format

Adrian Dragulescu adrian_d at eskimo.com
Tue Feb 14 04:05:27 CET 2006



>From the help page of format, nsmall should control the number of digits.

>      format(0.123456789, nsmall = 10)
[1] "0.1234567890"
>      format(0.123456789, nsmall = 1)
[1] "0.1234568"
>      format(0.123456789, nsmall = 2)
[1] "0.1234568"
>      format(0.123456789, nsmall = 8)
[1] "0.12345679"

It adds zeros fine but for format(0.123456789, nsmall = 1) I want the
result to be 0.1.

I want to format numbers with a fixed number of digits.  A combination of
round and format + nsmall does the job.  sprintf will do it too, but I
wondered if the current implementation of nsmall in format is correct.

Thanks,

Adrian




More information about the R-help mailing list