1 package C4::Format; #assumes C4/Format
7 use vars qw($VERSION @ISA @EXPORT);
9 # set the version for version checking
13 @EXPORT = qw(&fmtstr &fmtdec);
16 # format (space pad) a string
17 # $fmt is Ln.. or Rn.. where n is the length
18 my ($env,$strg,$fmt)=@_;
19 my $align = substr($fmt,0,1);
20 my $lenst = substr($fmt,1,length($fmt)-1);
22 $strg = substr((" "x$lenst).$strg,0-$lenst,$lenst);
23 } elsif ($align eq "C" ) {
25 substr((" "x(($lenst/2)-(length($strg)/2))).$strg.(" "x$lenst),0,$lenst);
27 $strg = substr($strg.(" "x$lenst),0,$lenst);
35 my ($env,$numb,$fmt)=@_;
36 my $curr = substr($fmt,0,1);
38 $fmt = substr($fmt,1,length($fmt)-1);
40 my $comma = substr($fmt,0,1);
42 $fmt = substr($fmt,1,length($fmt)-1);
45 my $left = substr($fmt,0,1);
46 if (length($fmt) == 1) {
49 $right = substr($fmt,1,1);
54 if (index($numb,".") == 0 ){
56 $tempdec = substr($numb,1,length($numb)-1);
58 if (index($numb,".") > 0) {
59 my $decpl = index($numb,".");
60 $tempint = substr($numb,0,$decpl);
61 $tempdec = substr($numb,$decpl+1,length($numb)-1-$decpl);
67 while (length($tempdec) > 3) {
68 $fnumb = ",".substr($tempint,-3,3).$fnumb;
69 substr($tempint,-3,3) = "";
71 $fnumb = substr($tempint,-3,3).$fnumb;
77 $fnumb = fmtstr($env,$curr.$fnumb,"R".$left+1);
82 $fnumb = fmtstr($env,$fnumb,"R".$left);
86 $tempdec = $tempdec.("0"x$right);
87 $tempdec = substr($tempdec,0,$right);
88 $fnumb = $fnumb.".".$tempdec;
93 END { } # module clean-up code here (global destructor)