[interchange-cvs] interchange - heins modified lib/Vend/Util.pm
interchange-core@interchange.redhat.com
interchange-core@interchange.redhat.com
Thu Nov 15 06:13:00 2001
User: heins
Date: 2001-11-15 11:12:54 GMT
Modified: lib/Vend Tag: STABLE_4_8-branch Util.pm
Log:
* Make round_to_frac_digits() work even if frac_digits are
zero. 8-)
Problem investigated and detailed by Shozo Murahashi
<murahashi@ayayu.com>. Thanks to him.
Revision Changes Path
No revision
No revision
2.1.2.2 +23 -3 interchange/lib/Vend/Util.pm
rev 2.1.2.2, prev_rev 2.1.2.1
Index: Util.pm
===================================================================
RCS file: /anon_cvs/repository/interchange/lib/Vend/Util.pm,v
retrieving revision 2.1.2.1
retrieving revision 2.1.2.2
diff -u -r2.1.2.1 -r2.1.2.2
--- Util.pm 2001/10/31 22:23:19 2.1.2.1
+++ Util.pm 2001/11/15 11:12:54 2.1.2.2
@@ -1,6 +1,6 @@
# Vend::Util - Interchange utility functions
#
-# $Id: Util.pm,v 2.1.2.1 2001/10/31 22:23:19 mheins Exp $
+# $Id: Util.pm,v 2.1.2.2 2001/11/15 11:12:54 mheins Exp $
#
# Copyright (C) 1996-2001 Red Hat, Inc. <interchange@redhat.com>
#
@@ -74,7 +74,7 @@
use Errno;
use subs qw(logError logGlobal);
use vars qw($VERSION @EXPORT @EXPORT_OK);
-$VERSION = substr(q$Revision: 2.1.2.1 $, 10);
+$VERSION = substr(q$Revision: 2.1.2.2 $, 10);
BEGIN {
eval {
@@ -198,7 +198,27 @@
# use what we were given
}
elsif ( $Vend::Cfg->{Locale} ) {
- $digits = $Vend::Cfg->{Locale}{frac_digits} || 2;
+ $digits = $Vend::Cfg->{Locale}{frac_digits};
+ $digits = 2 if ! defined $digits;
+ }
+ else {
+ $digits = 2;
+ }
+ my @frac;
+ $num =~ /^(\d*)\.(\d+)$/
+ or return $num;
+ my $int = $1;
+ @frac = split //, $2;
+ local($^W) = 0;
+ my $frac = join "", @frac[0 .. $digits - 1];
+ if($frac[$digits] > 4) {
+ $frac++;
+ }
+ if(length($frac) > $digits) {
+ $int++;
+ $frac = 0 x $digits;
+ }
+ $frac .= '0' while length($frac) < $digits;
}
else {
$digits = 2;