print flips to scientific notation when integer exceeds 15 decimal digits

PERL

    Next

  • 1. Question: Array of Hashes
    On Thu, 31 Mar 2005 14:40:47 +0200, Olivier, Wim W wrote: > Hi all, > > I have the following code below which I need to modify a bit. > > The script currently lists the key/value pairs for all processes in the > system. > What I need to achieve is for it to only list the key/value pairs for > processes of which the "Description" key is of a certain ASCII value, say > "analytics.exe". > Untested, but here goes: foreach my $info (@info) { if ($info->{'Description'} eq "analytics.exe") { foreach ('ProcessId', 'Description', 'ThreadCount') { print "$_ = ", $info->{$_} || '', "\n"; } print "\n"; } } Hope this helps, -- Offer Kaye
  • 2. t/ framework
    Hi there, I frequently come across this "module uses the t/ framework". What its all about? What functionality does it provide? Thanks, Manish
  • 3. General questions
    Hello, 1. I read on many Perl/CGI tutorial/articles that it is best to place and use CGI files in /cgi-bin/ directory than anywhere else, due to avoid many problems. Buy in our website, we have several subdomain and those are all use the same /cgi-bin/ directory, so now there are a lot of files populated there. So now what I have to do to reduce the management/maintanence problems. 2. I used "use strict", and I get error for the statement open(IN_FILE1, ">>test_records.txt"); Here the error is Bareword "IN_FILE1" not allowed while "strict subs" in use .... But if I remove "use strict", the program works well. So should I definately do not use "use strict" if the program want to handle I/O files? Thank you all. Greetings, R. Kumaran
  • 4. Need first line of Excel Spreadsheet
    I have a directory which has output reports in them. The big problem is that they are just a bunch of letters and numbers like 2781424330fdac47c916.xls. So the user would like a more recognizable file name. This is to run on Solaris w/ Perl 5.8.3. I have tried the following two modules on my PC using ActiveState 5.8.3 under XP: Spreadsheet::ParseExcel ( 15 minutes plus to read 4 files size 4 to 12 meg) and Spreadsheet::ParseExcel::Simple ( 4 minutes for the same files as ParseExcel ) I am running my first test on Solaris using Simple and the first file took 5 minutes to process. Still have 3 to do. Any suggestions on what to do? The key for naming the file is ( believe it or not ) the last column of the first row on worksheet 1. Any questions and/or problems, please let me know. Thanks! Wags ;) WGO: x2224 ******************************************************* This message contains information that is confidential and proprietary to FedEx Freight or its affiliates. It is intended only for the recipient named and for the express purpose(s) described therein. Any other use is prohibited. *******************************************************

Re: print flips to scientific notation when integer exceeds 15 decimal digits

Postby David.Lee » Thu, 05 Nov 2009 20:56:02 GMT




Many thanks for the reply.

Following the initial surprise, my main concern was that attempts to 
unearth a description or explanation (i.e. documentation) for the 
observed behaviour was so tricky.  For instance, there was nothing 
obvious in the relevant parts of "Programming Perl".

So I'm happy to categorise it as "self bug", although I'd like to 
include an element of "documentation weakness" in there and I'd be happy 
to assist someone in trying to improve the latter.

Anyway, your explanation was useful and gives us sufficient to decide 
how to address our local use of these numbers.  (In our case, they are 
human-oriented accumulated byte-counts, for which we don't actually need 
that significance/precision.)

Thanks.

-- 
: David Lee
: ECMWF (Data Handling System)
: Shinfield Park
: Reading  RG2 9AX
: Berkshire
:
: tel:    +44-118-9499 362
: email:   XXXX@XXXXX.COM 

Re: print flips to scientific notation when integer exceeds 15 decimal digits

Postby David.Lee » Fri, 06 Nov 2009 18:48:41 GMT



Thanks.

In fact, I had already realised that, but my earlier reply email 
inadvertently didn't acknowledge that known distinction, namely between:
  (1) how to perform the accumulation where, as you say, we certainly 
need to consider such issues (lots of relatively small increments to a 
growingly huge number) and:
  (2) how to present that information in its various outputs (which is 
where I had initially been "surprised"...)

All the best.

-- 
: David Lee
: ECMWF (Data Handling System)
: Shinfield Park
: Reading  RG2 9AX
: Berkshire
:
: tel:    +44-118-9499 362
: email:   XXXX@XXXXX.COM 

Similar Threads:

1.print flips to scientific notation when integer exceeds 15 decimal digits

Although I've used perl for many years, I've just been surprised (in the 
unpleasant sense) by a recent event.  Given a variable, say "$int", 
which is a growing integer, I would expect "print $int" to print it as a 
simple integer; indeed it usually does so.  But when its size takes it 
from 15 decimal digits to 16 decimal digits, that "print" flips the 
output into scientific notation:
    999999999999997
    999999999999998
    999999999999999
    1e+15
    1e+15

Ouch.  The surprise is especially nasty when this output data is then 
used as input data for another program that expects an integer.

This is consistent across a variety of OSes (although all perl 5.8.8).

I eventually managed to track down a way to achieve the desired result 
with a non-obvious "printf" format.  (I leave that, and its clear 
user-oriented explanation, as an exercise for the reader!)

I'm not aware of any documentation about this surprise. Is this a 
program bug or a documentation bug?  (Or a self bug?)

Is there a more appropriate forum than "beginners@..." to raise this?

-- 
: David Lee
: ECMWF (Data Handling System)
: Shinfield Park
: Reading  RG2 9AX
: Berkshire
:
: tel:    +44-118-9499 362
: email:   XXXX@XXXXX.COM 

2.Convert Scientific Notation to decimal equivalent

How can I detect this, I have been running some code for a few days to develop some files and ran into the situation where I am getting the following data for input:

14.95313 14.45312 0
14.95313 1.570813E-015 0
14.95313 -14.45313 0
-14.95313 -28.90625 0
-14.95313 -14.45313 0
-14.95313 1.570813E-015 0
-14.95313 14.45312 0
14.95313 -28.90625 0
0 -28.90625 0
-14.95313 28.90625 0
0 28.90625 0
14.95313 28.90625 0

And my code is skipping some lines as it checks for any erroneous data:
next if grep (/[^0-9.-]/, @data);
But that thinks the scientific notation is bad. I searched the net and didn't find anything. How can I match this specific pattern and convert it?

Thanks!
jlc



3.Number with More then 15 Digits.

 
Hi 

$a = 1234567890123456789; 
printf ("%0.0f\n", $a);

Out Put is 
1234567890123456800

which is wrong can any one let me know how do we handle 
Digits More than 15 digits ..

Regards
Govardhan MV


4.Newbie quesion: Scientific notation

Anno Siegel wrote:
> < XXXX@XXXXX.COM > wrote in comp.lang.perl.misc:
> > Hi,
> >
> > I'm trying to upload some data into a MySQL database.
> >
> > Could someone please advise me how I handle scientific notation?
> >
> > What I have sofar:
> >
> > -------
> > The data (pt, x)
> >
> > P1   4.50015068000000D-004
> > -------
> >
> > My regex expressions, I've been experimenting with:
> >
> > regex1: P\d+\s+(-?([0-9]+(\.[0-9]*)?|\.[0-9]+))/)
>           ^                                      ^^
> Are these supposed to be regex delimiters?
>
> > does not catch the scientific notation
>
> Of course not.  What makes you think it would?
>
> > regex2: P\d+\s+([+-]?(\d+(\.\d*)?|\.\d+)([eEdD][+-]?\d+))/)
> > does catch the scientific notation.  I then say,
> > $number = $1;
>
> For matching numbers with regular expressions, see perldoc -q "is a
number".
> Follow the pointers you find there.
Ah, this helps alot thanks!  I just didn't find that before.
>
> > -------
> > # Insert data
> > $dbh->do("INSERT INTO data(x) VALUES (?)",undef, $number);
> > -------
> >
> > How do I upload the number to the database?  If I do it as above it
is
> > incorrect.
>
> Incorrect how?  Is the data rejected by the database?  Is it accepted
> but not the values you expect it to be?  Be specific.
Well the number it uploads is not the float, in this case double, that
I want it to be.  I'll need to do a strtod.
> 
> Anno
Martin.

5.Newbie quesion: Scientific notation

Hi,

I'm trying to upload some data into a MySQL database.

Could someone please advise me how I handle scientific notation?

What I have sofar:

-------
The data (pt, x)

P1   4.50015068000000D-004
-------

My regex expressions, I've been experimenting with:

regex1: P\d+\s+(-?([0-9]+(\.[0-9]*)?|\.[0-9]+))/)
does not catch the scientific notation

regex2: P\d+\s+([+-]?(\d+(\.\d*)?|\.\d+)([eEdD][+-]?\d+))/)
does catch the scientific notation.  I then say,
$number = $1;

-------
# Insert data
$dbh->do("INSERT INTO data(x) VALUES (?)",undef, $number);
-------

How do I upload the number to the database?  If I do it as above it is
incorrect.

Thanks your help.

Martin.

6. Activestate PERL and ASE 15 OCS 15

7. Need help converting Perl to Ruby (detecting integers and decimals in strings)

8. Need > 15 digits precision without big performance hit



Return to PERL

 

Who is online

Users browsing this forum: No registered users and 99 guest