### Problem with OLE Excel

 on Jan 07, 2010 at 22:13 UTC Need Help??
Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks,

I am writing a simple script, where I am counting a list of big numbers andtotaling them. Total count I am writing into excel file (using win32::ole for this).

The Totaling number is 4264859333. as you can see it's 10 digit. Instead of seeing this number in excel, I am seeing a negative number -30107963.

Replies are listed 'Best First'.
Re: Problem with OLE Excel
by ikegami (Pope) on Jan 07, 2010 at 22:20 UTC
Perl stored the number as an unsigned 2's complement, but something along the way treated it as an signed 2's complement
```-30107963 + 2**32 = 4264859333

I don't know who exactly is at fault, and what can be done to fix it.

Update: Forcing the number to be stored as a float internally might do the trick. The following does that:

```\$x = \$x + 0.5 - 0.5;

He He Ho Ho Hi Hi ... It worked. force Storing it as float. Thank You Teacher :)

Thanks ikegami for the suggestion. One more thing just point out .. is that ... data is getting populated properly but at the time of formating the sheet it's gettig changed to negative number.

Hmmm ... really typical behavior :)

Re: Problem with OLE Excel
by gam3 (Curate) on Jan 08, 2010 at 00:04 UTC
If you need even bigger numbers look at Math::BigInt.
-- gam3
A picture is worth a thousand words, but takes 200K.

I doubt OLE speaks in BigInts... Besides, at ten digits, he's nowhere near the point where they'd be needed. Perl and OLE can accurately represent with numbers up to 16 digits long, and they can represent numbers up to 308 digits long (with 53 bits of precision).

Hi,

Yes, I agree with ikegami. as far I know Math::BigInt is for very big numbers. I don't need them as in my case highest is 11 digit number I have.

Create A New User
Node Status?
node history
Node Type: perlquestion [id://816180]
Approved by Corion
help
Chatterbox?
 [holli]: this really really should not be executed as Javascript erix's head is getting content indisposed [holli]: maybe try a GET instead? [moritz]: I must say, when I was very active on perlmonks, I got really used to the markup and all the workflows [moritz]: and then I didn't post for a while, and then tried to answer a question. It nearly drove me nuts [moritz]: when you try to quote part of a question, you have to know/guess/reverse -engineer what kind of markup they used [holli]: [moritz]: and stuff it into a
..., which is, like, not at all bulky [moritz]: specially if you're used to markdown [holli]: there probably is some nodelet hack that lets you use markdown :)

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (10)
As of 2017-11-20 19:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
In order to be able to say "I know Perl", you must have:

Results (291 votes). Check out past polls.

Notices?