summaryrefslogtreecommitdiff
path: root/LedgerSMB
diff options
context:
space:
mode:
authoreinhverfr <einhverfr@4979c152-3d1c-0410-bac9-87ea11338e46>2006-10-20 15:53:54 +0000
committereinhverfr <einhverfr@4979c152-3d1c-0410-bac9-87ea11338e46>2006-10-20 15:53:54 +0000
commit2ae1d72333c58b19687f2c1d2385a6bb6ef29596 (patch)
tree7f8091f61fc048c2a86fe461977b37f51adb0bbf /LedgerSMB
parentd89d93773f1ba6e2db81fb2adb8127d5b63b9842 (diff)
Moved ->parse_amount() to use Math::BigFloats to avoid issues of double-parsing
git-svn-id: https://ledger-smb.svn.sourceforge.net/svnroot/ledger-smb/trunk@242 4979c152-3d1c-0410-bac9-87ea11338e46
Diffstat (limited to 'LedgerSMB')
-rwxr-xr-xLedgerSMB/Form.pm16
1 files changed, 12 insertions, 4 deletions
diff --git a/LedgerSMB/Form.pm b/LedgerSMB/Form.pm
index 3a22392f..f305690a 100755
--- a/LedgerSMB/Form.pm
+++ b/LedgerSMB/Form.pm
@@ -388,13 +388,18 @@ sub format_amount {
my ($self, $myconfig, $amount, $places, $dash) = @_;
+ my $negative = ($amount < 0);
+ if ($amount){
+ $amount =~ s/-//;
+ $amount = $self->parse_amount($myconfig, $amount);
+ }
+
if ($places =~ /\d+/) {
#$places = 4 if $places == 2;
$amount = $self->round_amount($amount, $places);
}
# is the amount negative
- my $negative = ($amount < 0);
# Parse $myconfig->{numberformat}
@@ -406,8 +411,6 @@ sub format_amount {
if ($myconfig->{numberformat}) {
- $amount =~ s/-//;
- $amount = $self->parse_amount($amount, $myconfig);
my ($whole, $dec) = split /\./, "$amount";
$amount = join '', reverse split //, $whole;
@@ -486,8 +489,12 @@ sub parse_amount {
my ($self, $myconfig, $amount) = @_;
+ eval $amount->isa('Math::BigFloat'); # Amount may not be an object
+ if (!$@ and $amount->isa('Math::BigFloat')){
+ return $amount;
+ }
my $numberformat = $myconfig->{numberformat};
- my $decimal_regex = /\.\d{2}/;
+ my $decimal_regex = /\.\d+$/;
if (($numberformat !~ $decimal_regex) and ($amount =~ $decimal_regex)){
# We have already parsed this number
$numberformat = "1000.00";
@@ -508,6 +515,7 @@ sub parse_amount {
}
$amount =~ s/,//g;
+ $amount = new Math::BigFloat($amount);
return ($amount * 1);
}