Re: [R] Number of digits of a value for problem 7.31 RFAQ SOLVED not really

From: <>
Date: Mon, 18 Feb 2008 17:32:46 +0000

> Actually (after some trials) there is a little problem when faced with
> zeros...
> >getndp(1.0)
> [1] 0

Are you sure this isn't what you want? 1.0 is just 1 in disguise, and round(1.0, 0) is the same as round(1.0, 1) anyway.

> Note that I thought on a very different way which was starting from the
> point that as.character seems to work:
> a<-as.character(1.23134)
> b<-strsplit(a,"\\.")
> nchar(b)

I think the last line should be:


If you choose this route, be careful with R clipping your values. e.g.
 x <- 0.12345678901234567890123456789

format(x, nsmall=20)
[1] "0.12345678901234567737" #this is what is stored (actually some binary number, this is the closest decimal representation)

a <- as.character(x); a
[1] "0.123456789012346" #

[1] 15


Mathematical Sciences Unit

ATTENTION: This message contains privileged and confidential inform...{{dropped:20}} mailing list PLEASE do read the posting guide and provide commented, minimal, self-contained, reproducible code. Received on Mon 18 Feb 2008 - 17:35:36 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Mon 18 Feb 2008 - 18:30:15 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.

list of date sections of archive