X-Git-Url: http://wagnertech.de/gitweb/gitweb.cgi/kivitendo-erp.git/blobdiff_plain/cb9ded864a5b5f6fa6da8a04e37983bd3e6cdf63..becc49b1374f60cd4c8b389490859e92a99ae572:/SL/Form.pm diff --git a/SL/Form.pm b/SL/Form.pm index 25886980a..d6cbc0b7c 100644 --- a/SL/Form.pm +++ b/SL/Form.pm @@ -540,19 +540,19 @@ sub format_amount { $amount =~ s/\d{3,}?/$&,/g; $amount =~ s/,$//; $amount = join '', reverse split //, $amount; - $amount .= "\.$dec".$fillup; + $amount .= "\.$dec".$fillup if ($places ne '' && $places*1 != 0); } if ($myconfig->{numberformat} eq '1.000,00') { $amount =~ s/\d{3,}?/$&./g; $amount =~ s/\.$//; $amount = join '', reverse split //, $amount; - $amount .= ",$dec" .$fillup; + $amount .= ",$dec".$fillup if ($places ne '' && $places*1 != 0); } if ($myconfig->{numberformat} eq '1000,00') { $amount = "$whole"; - $amount .= ",$dec" .$fillup; + $amount .= ",$dec" .$fillup if ($places ne '' && $places*1 != 0); } if ($dash =~ /-/) { @@ -604,26 +604,21 @@ sub round_amount { $main::lxdebug->enter_sub(); my ($self, $amount, $places) = @_; - my $rc; + my $round_amount; - # $places = 3 if $places == 2; - - if (($places * 1) >= 0) { - - # add 1/10^$places+3 - $rc = - sprintf("%.${places}f", - $amount + (1 / (10**($places + 3))) * (($amount > 0) ? 1 : -1)); - } else { - $places *= -1; - $rc = - sprintf("%.f", $amount / (10**$places) + (($amount > 0) ? 0.1 : -0.1)) * - (10**$places); - } + # Rounding like "Kaufmannsrunden" + # Descr. http://de.wikipedia.org/wiki/Rundung + # Inspired by + # http://www.perl.com/doc/FAQs/FAQ/oldfaq-html/Q4.13.html + # Solves Bug: 189 + # Udo Spallek + $amount = $amount * (10 ** ($places)); + $round_amount = int($amount + .5 * ($amount <=> 0))/(10**($places)); $main::lxdebug->leave_sub(); - return $rc; + return $round_amount; + }