Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision a8b411e2

Von Udo Spallek vor fast 19 Jahren hinzugefügt

  • ID a8b411e2d4c2935623ba94966503e5d40a3af409
  • Vorgänger 43cbbf5a
  • Nachfolger 95cac184

Bug 189: Patch zum Rundungsfehler

Unterschiede anzeigen:

SL/Form.pm
565 565
  $main::lxdebug->enter_sub();
566 566

  
567 567
  my ($self, $amount, $places) = @_;
568
  my $rc;
568
  my $round_amount;
569 569

  
570
  #  $places = 3 if $places == 2;
571

  
572
  if (($places * 1) >= 0) {
573

  
574
    # add 1/10^$places+3
575
    $rc =
576
      sprintf("%.${places}f",
577
              $amount + (1 / (10**($places + 3))) * (($amount > 0) ? 1 : -1));
578
  } else {
579
    $places *= -1;
580
    $rc =
581
      sprintf("%.f", $amount / (10**$places) + (($amount > 0) ? 0.1 : -0.1)) *
582
      (10**$places);
583
  }
570
  # Rounding like "Kaufmannsrunden"
571
  # Descr. http://de.wikipedia.org/wiki/Rundung
572
  # Inspired by 
573
  # http://www.perl.com/doc/FAQs/FAQ/oldfaq-html/Q4.13.html
574
  # Solves Bug: 189
575
  # Udo Spallek
576
  $amount       = $amount * (10 ** ($places));
577
  $round_amount = int($amount + .5 * ($amount <=> 0))/(10**($places));
584 578

  
585 579
  $main::lxdebug->leave_sub();
586 580

  
587
  return $rc;
581
  return $round_amount;
588 582
}
589 583

  
590 584
sub parse_template {

Auch abrufbar als: Unified diff