From 2ae1d72333c58b19687f2c1d2385a6bb6ef29596 Mon Sep 17 00:00:00 2001 From: einhverfr Date: Fri, 20 Oct 2006 15:53:54 +0000 Subject: 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 --- LedgerSMB/Form.pm | 16 ++++++++++++---- 1 file 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); } -- cgit v1.2.3