[R] How many digits are there in left of dot of 0.0001 ?

ce zadig_1 at excite.com
Thu Feb 26 12:22:05 CET 2015


yes this is exactly what I want and it works. thanks.

-----Original Message-----
From: "JS Huang" [js.huang at protective.com]
Date: 02/26/2015 03:22 AM
To: r-help at r-project.org
Subject: Re: [R] How many digits are there in left of dot of 0.0001 ?

Hi,

  To get the number of digits to the right of decimal point: 
nchar(format(a,scientific=FALSE))-(trunc(log10(max(1,trunc(abs(a)))))+1) -1.  

  The part (trunc(log10(max(1,trunc(abs(a)))))+1) is the number of digits to
the left of decimal.  At the end, subtract 1 for the decimal point.

  Negative number needs more work.

> options(digits=10)
> a <- 0.0001
> nchar(format(a,scientific=FALSE))-(trunc(log10(max(1,trunc(abs(a)))))+1)
> -1
[1] 4
> a <- 999.123456
> nchar(format(a,scientific=FALSE))-(trunc(log10(max(1,trunc(abs(a)))))+1)
> -1
[1] 6



--
View this message in context: http://r.789695.n4.nabble.com/How-many-digits-are-there-in-left-of-dot-of-0-0001-tp4703842p4703849.html
Sent from the R help mailing list archive at Nabble.com.

______________________________________________
R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
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