Author: spadkins
Date: Tue Apr 17 05:18:08 2007
New Revision: 9423
Modified:
p5ee/trunk/App-Repository/bin/dbget
Log:
add decimals option
Modified: p5ee/trunk/App-Repository/bin/dbget
==============================================================================
--- p5ee/trunk/App-Repository/bin/dbget (original)
+++ p5ee/trunk/App-Repository/bin/dbget Tue Apr 17 05:18:08 2007
@@ -3,7 +3,7 @@
use Date::Format;
use App::Options (
- options => [ qw(dbhost dbname dbuser dbpass repository table params
columns headings compact subtotal_columns totals verbose) ],
+ options => [ qw(dbhost dbname dbuser dbpass repository table params
columns headings compact decimals subtotal_columns totals verbose) ],
option => {
repository => {
default => "default",
@@ -26,6 +26,10 @@
compact => {
description => "Trim titles to make compact table",
},
+ decimals => {
+ description => "Number of decimal places to print on floats",
+ default => "2",
+ },
subtotal_columns => {
description => "Print sub-totals at the end",
},
@@ -127,7 +131,7 @@
$elem = $row->[$c];
$len = length($elem);
if ($elem =~ /^-?[0-9]*\.[0-9]+$/) { # float
- $len = length(sprintf("%.2f",$elem));
+ $len = length(sprintf("%.$App::options{decimals}f",$elem));
$f->{type} = 1 if ($f->{type} > 1);
if (!defined $f->{min} || $elem < $f->{min}) {
$f->{min} = $elem;
@@ -177,7 +181,7 @@
my ($width, $int_len, $fract_len);
if ($f->{type} == 1) { # float
$f->{title_fmt} = "%$f->{max_length}.$f->{max_length}s";
- $f->{fmt} = "%$f->{max_length}.2f";
+ $f->{fmt} = "%$f->{max_length}.$App::options{decimals}f";
}
elsif ($f->{type} == 2) { # integer
$f->{title_fmt} = "%$f->{max_length}.$f->{max_length}s";