From becc49b1374f60cd4c8b389490859e92a99ae572 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Stephan=20K=C3=B6hler?= Date: Fri, 25 Nov 2005 12:20:05 +0000 Subject: [PATCH] =?utf8?q?Merge=20von=20581,589-595=20aus=20unstable:=20Pa?= =?utf8?q?tch=20zum=20Rundungsfehler=20-Bug=20189:=20Patch=20zum=20Rundung?= =?utf8?q?sfehler=20-sub=20round=5Famount=20schnedet=20nun=20anh=C3=A4ngen?= =?utf8?q?de=20Nullen=20automatisch=20ab.=20-=C3=84nderungen=20bez.=20sub?= =?utf8?q?=20round=5Famound=20von=20heute=20Morgen=20wieder=20herausgenomm?= =?utf8?q?en,=20weil=20nonfunktional.=20Das=20problem=20scheint=20woanders?= =?utf8?q?=20zu=20liegen.=20-Darstellungsfehler=20bei=20Ganzzahlen=20behob?= =?utf8?q?en.=20Vorher=20wurde=20bspw.=20'2'=20als=20'2,'=20dargestellt,?= =?utf8?q?=20nun=20wird=20richtig=20formatiert.=20-Die=20Anzahl=20der=20da?= =?utf8?q?rgestellten=20Nachkommastellen=20jedes=20einzelnen=20Preises=20s?= =?utf8?q?ollte=20mit=20der=20eingegebenen=20Anzahl=20=20an=20Nachkommaste?= =?utf8?q?llen=20=C3=BCbereinstimmen.=20Die=20eingegebenen=20Preise=20soll?= =?utf8?q?ten=20nicht=20gerundet=20werden.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- SL/Form.pm | 33 ++++++++++++++------------------- bin/mozilla/ic.pl | 12 +++++++++++- 2 files changed, 25 insertions(+), 20 deletions(-) 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; + } diff --git a/bin/mozilla/ic.pl b/bin/mozilla/ic.pl index 81db76741..6d49eab28 100644 --- a/bin/mozilla/ic.pl +++ b/bin/mozilla/ic.pl @@ -1955,6 +1955,16 @@ sub link_part { sub form_header { $lxdebug->enter_sub(); + my $dec = ''; + + #decimalplaces for listprice + ($dec) = ($form->{listprice} =~ /\.(\d+)/); + $dec = length $dec; + my $decimalplaces = ($dec > 2) ? $dec : 2; + $form->{listprice} = + $form->format_amount(\%myconfig, $form->{listprice}, $decimalplaces); + + #decimalplaces for sellprice and gv ($dec) = ($form->{sellprice} =~ /\.(\d+)/); $dec = length $dec; my $decimalplaces = ($dec > 2) ? $dec : 2; @@ -1962,7 +1972,7 @@ sub form_header { map { $form->{$_} = $form->format_amount(\%myconfig, $form->{$_}, $decimalplaces) - } qw(listprice sellprice gv); + } qw(sellprice gv); ($dec) = ($form->{lastcost} =~ /\.(\d+)/); $dec = length $dec; -- 2.20.1