[Denver-pm] Scientific Notation -> Dec?????

Larry Leszczynski larryl at emailplus.org
Wed Jul 23 13:36:08 PDT 2014


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


More information about the Denver-pm mailing list