[Denver-pm] Scientific Notation -> Dec?????
Robert L. Harris
robert.l.harris at gmail.com
Thu Jul 24 08:17:05 PDT 2014
I'm pretty sure I tried that except with the sprintf ( the examples I found
online only had sprint instead of printf ) and no change but I'll
definitely try again.
Thanks
On Thu, Jul 24, 2014 at 8:27 AM, Larry Leszczynski <larryl at emailplus.org>
wrote:
> Hi Robert -
>
> On Wed, Jul 23, 2014, at 06:00 PM, Robert L. Harris wrote:
> > They are being inserted into a database but the db doesn't recognize that
> > as a number. So I have to convert it to -0.00007800825 before the
> > insert.
>
> I think you could just do:
>
> if ($State =~ /[Ee]/) {
> $State = printf "%.12f", $State;
> }
>
> E.g.:
>
> $ perl -e 'printf "%.12f\n", "-7.7800825E-05"'
> -0.000077800825
> $ perl -e 'printf "%.12f\n", "-7.7800825e-05"'
> -0.000077800825
>
>
> HTH,
> Larry
>
>
> >
> >
> >
> > On Wed, Jul 23, 2014 at 2:36 PM, Larry Leszczynski <larryl at emailplus.org
> >
> > wrote:
> >
> > > Hi Robert -
> > >
> > > > OK, I'm parsing through a bunch of data. Occasionally I get
> something
> > > > like
> > > > :
> > > > $State="-7.7800825e-05"
> > > >
> > > > Usually the "e" is capital ( I don't know why this product logs it
> this
> > > > way
> > > > ). When the Capital E goes through the if statements below it
> converts
> > > > fine, but the lower case does not it seems...
> > > >
> > > > I have put in the following sections to convert this:
> > > >
> > > > $State =~ tr/e/E/;
> > > >
> > > > if ( $State =~ /E/ ) {
> > > > $State2 = sprintf("%.10g", $State);
> > > > $State=$State2;
> > > > }
> > > > if ( $State =~ /e/ ) {
> > > > $State2 = sprintf("%.10g", $State);
> > > > $State=$State2;
> > > > }
> > >
> > > What are you trying to do with these values? If you use them in
> numeric
> > > context, they work fine as-is, no matter if they have a "e" or "E":
> > >
> > > $ perl -de 0
> > >
> > > Loading DB routines from perl5db.pl version 1.32
> > > Editor support available.
> > >
> > > Enter h or `h h' for help, or `man perldebug' for more help.
> > >
> > > main::(-e:1): 0
> > > DB<1> print 0 + "-7.7800825e-05"
> > > -7.7800825e-05
> > > DB<2> print 0 + "-7.7800825E-05"
> > > -7.7800825e-05
> > >
> > >
> > > Larry
> > > _______________________________________________
> > > Denver-pm mailing list
> > > Denver-pm at pm.org
> > > http://mail.pm.org/mailman/listinfo/denver-pm
> > >
> >
> >
> >
> > --
> > :wq!
> >
> ---------------------------------------------------------------------------
> > Robert L. Harris
> >
> > DISCLAIMER:
> > These are MY OPINIONS With Dreams To Be A King,
> > ALONE. I speak for First One Should Be A Man
> > no-one else. - Manowar
>
--
:wq!
---------------------------------------------------------------------------
Robert L. Harris
DISCLAIMER:
These are MY OPINIONS With Dreams To Be A King,
ALONE. I speak for First One Should Be A Man
no-one else. - Manowar
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/denver-pm/attachments/20140724/23e15396/attachment-0001.html>
More information about the Denver-pm
mailing list