Sorry I meant right. I want to do it R of course. result should be 4 naturally. On the left answer I want would be 1 , -----Original Message----- From: "Hasan Diwan" [hasan.diwan at gmail.com] Date: 02/25/2015 09:28 PM To: "R Project Help" <r-help at r-project.org> Subject: Re: [R] How many digits are there in left of dot of 0.0001 ? On 25 February 2015 at 17:55, ce <zadig_1 at excite.com> wrote:> Dear all, > > I would like to count how many digits are there on the left of a the dot > of a numeric variable >Left? An infinite number... What does this have to do with R, though? -- H> > a=0.0001 > > thanks > > ______________________________________________ > 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. >-- OpenPGP: https://hasan.d8u.us/gpg.key Sent from my mobile device Envoy? de mon portable [[alternative HTML version deleted]] ______________________________________________ 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
Hasan Diwan
2015-Feb-26 02:54 UTC
[R] How many digits are there in left of dot of 0.0001 ?
Ahh... The exponent of your number in scientific notation, which you can obtain using: format(a.number, scientific=TRUE) Hope that helps.. -- H On 25 February 2015 at 18:43, ce <zadig_1 at excite.com> wrote:> > Sorry I meant right. I want to do it R of course. result should be 4 > naturally. On the left answer I want would be 1 , > > -----Original Message----- > From: "Hasan Diwan" [hasan.diwan at gmail.com] > Date: 02/25/2015 09:28 PM > To: "R Project Help" <r-help at r-project.org> > Subject: Re: [R] How many digits are there in left of dot of 0.0001 ? > > On 25 February 2015 at 17:55, ce <zadig_1 at excite.com> wrote: > > > Dear all, > > > > I would like to count how many digits are there on the left of a the dot > > of a numeric variable > > > > Left? An infinite number... What does this have to do with R, though? -- H > > > > > a=0.0001 > > > > thanks > > > > ______________________________________________ > > 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. > > > > > > -- > OpenPGP: https://hasan.d8u.us/gpg.key > Sent from my mobile device > Envoy? de mon portable > > [[alternative HTML version deleted]] > > ______________________________________________ > 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 >-- OpenPGP: https://hasan.d8u.us/gpg.key Sent from my mobile device Envoy? de mon portable [[alternative HTML version deleted]]
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.