Author: spadkins
Date: Mon Jun 25 15:14:09 2007
New Revision: 9680
Modified:
p5ee/trunk/App-Widget/lib/App/Widget.pm
Log:
added a scale factor to the format string for the format method
Modified: p5ee/trunk/App-Widget/lib/App/Widget.pm
==============================================================================
--- p5ee/trunk/App-Widget/lib/App/Widget.pm (original)
+++ p5ee/trunk/App-Widget/lib/App/Widget.pm Mon Jun 25 15:14:09 2007
@@ -544,13 +544,34 @@
# ($#,###.##) currency. 2 digits precision. add commas as
necessary. negatives in parentheses.
# (#) integer. negatives in parentheses.
# (#.###) float. 3 digits precision. negatives in
parentheses.
- elsif ($format =~ /^(\(?)(\+?)(\$?)([#,]*)\.?(#*)(%?)[\)]*$/) {
- my $paren = $1;
- my $sign = $2;
- my $curr = $3;
- my $int = $4;
- my $frac = $5;
- my $pct = $6;
+ # #,### (/00) integer. scaled up by 100 (i.e. the number of
one-hundredths)
+ # #,### (000) integer. scaled down by 1000 (i.e. the number
of thousands)
+ # #,### (K) integer. scaled down by 1,000 (i.e. the number
of thousands)
+ # #,### (M) integer. scaled down by 1,000,000 (i.e. the
number of millions)
+ elsif ($format =~
/^(\(?)(\+?)(\$?)([#,]*)\.?(#*)(%?)[\)]*\s*(?:\((\/?)([^\(\)]+)\))?$/) {
+ my %scale_abbr = ( K => "000", M => "000000", G =>
"000000000", );
+ my $paren = $1;
+ my $sign = $2;
+ my $curr = $3;
+ my $int = $4;
+ my $frac = $5;
+ my $pct = $6;
+ my $scale_up = $7;
+ my $scale = $8;
+ if ($scale ne "") {
+ if (defined $scale_abbr{$scale}) {
+ $scale = $scale_abbr{$scale};
+ }
+ if ($scale =~ /^0+$/) {
+ $scale = "1$scale";
+ if ($scale_up) {
+ $formatted_value *= $scale;
+ }
+ else {
+ $formatted_value /= $scale;
+ }
+ }
+ }
my $negated = (($paren || $sign) && $value < 0);
if ($negated) {
$formatted_value = -$formatted_value;