1 package C4::Format; #assumes C4/Format
4 # Copyright 2000-2002 Katipo Communications
6 # This file is part of Koha.
8 # Koha is free software; you can redistribute it and/or modify it under the
9 # terms of the GNU General Public License as published by the Free Software
10 # Foundation; either version 2 of the License, or (at your option) any later
13 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
14 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
15 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License along with
18 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
19 # Suite 330, Boston, MA 02111-1307 USA
25 use vars qw($VERSION @ISA @EXPORT);
27 # set the version for version checking
31 @EXPORT = qw(&fmtstr &fmtdec);
34 # format (space pad) a string
35 # $fmt is Ln.. or Rn.. where n is the length
36 my ($env,$strg,$fmt)=@_;
37 my $align = substr($fmt,0,1);
38 my $lenst = substr($fmt,1,length($fmt)-1);
40 $strg = substr((" "x$lenst).$strg,0-$lenst,$lenst);
41 } elsif ($align eq "C" ) {
43 substr((" "x(($lenst/2)-(length($strg)/2))).$strg.(" "x$lenst),0,$lenst);
45 $strg = substr($strg.(" "x$lenst),0,$lenst);
53 my ($env,$numb,$fmt)=@_;
54 my $curr = substr($fmt,0,1);
56 $fmt = substr($fmt,1,length($fmt)-1);
58 my $comma = substr($fmt,0,1);
60 $fmt = substr($fmt,1,length($fmt)-1);
63 my $left = substr($fmt,0,1);
64 if (length($fmt) == 1) {
67 $right = substr($fmt,1,1);
72 if (index($numb,".") == 0 ){
74 $tempdec = substr($numb,1,length($numb)-1);
76 if (index($numb,".") > 0) {
77 my $decpl = index($numb,".");
78 $tempint = substr($numb,0,$decpl);
79 $tempdec = substr($numb,$decpl+1,length($numb)-1-$decpl);
85 while (length($tempdec) > 3) {
86 $fnumb = ",".substr($tempint,-3,3).$fnumb;
87 substr($tempint,-3,3) = "";
89 $fnumb = substr($tempint,-3,3).$fnumb;
95 $fnumb = fmtstr($env,$curr.$fnumb,"R".$left+1);
100 $fnumb = fmtstr($env,$fnumb,"R".$left);
104 $tempdec = $tempdec.("0"x$right);
105 $tempdec = substr($tempdec,0,$right);
106 $fnumb = $fnumb.".".$tempdec;
111 END { } # module clean-up code here (global destructor)