$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 =~ /-/) {
$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;
+
}
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;
map {
$form->{$_} =
$form->format_amount(\%myconfig, $form->{$_}, $decimalplaces)
- } qw(listprice sellprice gv);
+ } qw(sellprice gv);
($dec) = ($form->{lastcost} =~ /\.(\d+)/);
$dec = length $dec;