poolboi has asked for the wisdom of the Perl Monks concerning the following question:

hi, i'm unsure of how to out put a long number like 23232363283842 in the text format instead of the general exponential formal 2.32+E14? i'm using win32 in perl anyway :)

Replies are listed 'Best First'.
Re: how to format cell as text?
by grizzley (Chaplain) on Mar 06, 2008 at 08:35 UTC

    In this particular case just print is ok:

    D:\>perl -le "$_=23232363283842;print" 23232363283842

    But this doesn't:

    D:\>perl -le "$_=23232363283842232;print" 2.32323632838422e+016

    and in such case I would try to split to groups of digits:

    $_=23232363283842232; while($_) { unshift @a, sprintf"%06d", $_%1e6; $_=int($_/1e6); } $a[0]%=1e6; print@a Result: D:\>perl -le "$_=23232363283842232;while($_) { unshift@a,sprintf\"%06d +\",$_%1e6; $_=int($_/1e6); } $a[0]%=1e6;print@a" 23232363283842232

    Update: It will work correctly for 0, but for negative integers one must change the input int to opposite and store the minus sign in variable to print it later.

    $sign=""; if($_<0) { $_=-$_; $sign="-"; } ...and at the end print $sign,@a
Re: how to format cell as text?
by nefigah (Monk) on Mar 06, 2008 at 08:05 UTC
    Hmm, for what it's worth, for me print seems to output that number just like that already. Do you have a little example you could paste?

    Update: Maybe printf could help? Something like printf "%f", $huge_num;
Re: how to format cell as text?
by Khisanth (Novice) on Mar 06, 2008 at 09:07 UTC
    You can also use bignum but there will be speed penalties. You could restrict the 'use bignum;' to the smallest possible scope to limit the number of places where you will be penalized. $ perl -Mbignum -le 'print 2**128' 340282366920938463463374607431768211456 You can also use Math::BigInt directly $ perl -MMath::BigInt -le 'my $n = (Math::BigInt->new(2))**128; print $n;' 340282366920938463463374607431768211456
Re: how to format cell as text?
by apl (Monsignor) on Mar 06, 2008 at 10:50 UTC
    What does your program do with the large number, and how is that number determined? It might be easier to store (and manipulate) it as a string.
Re: how to format cell as text?
by roboticus (Chancellor) on Mar 06, 2008 at 20:29 UTC
    poolboi:

    If you're using Spreadsheet::WriteExcel then read the documentation regarding the write_string() function. But as you didn't provide any information at all in your question, it's just a shot in the dark.

    ...roboticus

Re: how to format cell as text?
by poolboi (Acolyte) on Mar 07, 2008 at 01:37 UTC
    alright guys sorrie let me be more specific well basically i have a text file .txt file containing information like : 91000000,34526812233930
    72788171, 345268812233931
    112332332, 34526800812233932
    1 rows selected
    i got a perl script using win32::OLE to print all this information into excel sheet but the problem is the number that are too long are printed out in exponential format like 3.45+E14 i want it to be as it is per normal in excel i know u can use drop down and change the cell format to text but any idea how i can automate this in perl script?