I want the data in tables without decimal values. I searched the options for doing the same in PDF::Table and PDF::API2 perl modules since i'm making use of these modules in my code. But i did not find any options. Please help me with this issue.
Asked
Active
Viewed 63 times
-2
-
Please show the code you are using to generate that table and some example data and example output. – simbabque May 28 '15 at 10:04
1 Answers
1
You could always just map the data through some function that removes the decimals. Here's some code, based on the synopsis of the PDF::Table POD.
use PDF::API2;
use PDF::Table;
my $pdftable = new PDF::Table;
my $pdf = new PDF::API2(-file => "table_of_lorem.pdf");
my $page = $pdf->page;
# some data to layout
my $some_data =[
[ 0, 0.1 .. 0.9 ],
[ 1, 1.1 .. 1.9 ],
#... and so on
];
$left_edge_of_table = 50;
# build the table layout
$pdftable->table(
# required params
$pdf,
$page,
remove_decimals($some_data), # here's our function
x => $left_edge_of_table,
w => 495,
start_y => 500,
start_h => 300,
# some optional params
next_y => 750,
next_h => 500,
padding => 5,
padding_right => 10,
background_color_odd => "gray",
background_color_even => "lightblue", #cell background color for even rows
);
And somewhere else we define the function remove_decimals
.
sub remove_decimals {
my ( $data ) = @_;
# we are making copies so we don't alter the original data
my $new_data = [];
foreach my $row ( @$data ) {
push @$new_data, map { int } @$row;
}
return $new_data;
}
Please note that this code is untested.

simbabque
- 53,749
- 8
- 73
- 136
-
I don't want to remove the decimals. Just want to round up the value. For instance, if the value is 10.83 it should convert to 11. – Vimal Kumar May 28 '15 at 11:18
-
-
1Your question says *How to remove the decimal part*. You can do rounding with basic Perl. `sprintf '%.0f', 10.83` will yield 11. See http://perldoc.perl.org/functions/sprintf.html. Also **please read the [faq#howtoask]**. – simbabque May 28 '15 at 11:42