Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

Hi Guys, I'm very new to perl. I was just doing some read/write operations in excel sheet using perl. My issue is: When i write a decimal number (fraction number. Ex : 2.5), and read it back, the output is some long number with extra decimals. I dont know why this is happening. Please help me

use Spreadsheet::ParseExcel; use Spreadsheet::ParseExcel::SaveParser; ## Write to an existing excel sheet $parser = Spreadsheet::ParseExcel::SaveParser->new(); my $workbook = $parser->Parse('myxls.xls'); # Get the first worksheet. my $worksheet = $workbook->worksheet("myxls"); my ( $row_min, $row_max ) = $worksheet->row_range(); my ( $col_min, $col_max ) = $worksheet->col_range(); $worksheet->AddCell( $row_max+1, 0, '10.1' ); $worksheet->AddCell( $row_max+1, 1, '10.2' ); $worksheet->AddCell( $row_max+1, 2, '10.3' ); $worksheet->AddCell( $row_max+1, 3, '10.4' ); $worksheet->AddCell( $row_max+1, 4, '10.5' ); $worksheet->AddCell( $row_max+1, 5, '10.6' ); $worksheet->AddCell( $row_max+1, 6, '10.7' ); $worksheet->AddCell( $row_max+1, 7, '10.8' ); $worksheet->AddCell( $row_max+1, 8, '10.9' ); $workbook->SaveAs('myxls.xls'); ## Excel Read $parser = Spreadsheet::ParseExcel::SaveParser->new(); my $workbook = $parser->Parse('myxls.xls'); # Get the first worksheet. my $worksheet = $workbook->worksheet("myxls"); my ( $row_min, $row_max ) = $worksheet->row_range(); my ( $col_min, $col_max ) = $worksheet->col_range(); for($r=$row_min; $r<=$row_max; $r++){ for($c=$col_min; $c<=$col_max; $c++){ $d = $worksheet->get_cell( $r, $c); if(defined $d) { $d= $d +->unformatted(); print "-$d-\t";} } print "\n"; }

Result : -10.0999999999999996- -10.1999999999999993- -10.3000000000000007- -10.4000000000000004- -10.5- -10.5999999999999996- -10.6999999999999993- -10.8000000000000007- -10.9000000000000004- I don't understand why this extra decimal numbers. When i open excel and check, this extra decimals are not there. Please help me


In reply to Issue while reading decimal number from a Spreadsheet using perl by KishKishore

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others taking refuge in the Monastery: (5)
    As of 2020-04-01 05:44 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      To "Disagree to disagree" means to:









      Results (186 votes). Check out past polls.

      Notices?