KishKishore has asked for the wisdom of the Perl Monks concerning the following question:
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


Back to
Seekers of Perl Wisdom