From a8b411e2d4c2935623ba94966503e5d40a3af409 Mon Sep 17 00:00:00 2001 From: Udo Spallek Date: Wed, 12 Oct 2005 08:38:07 +0000 Subject: [PATCH] Bug 189: Patch zum Rundungsfehler --- SL/Form.pm | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/SL/Form.pm b/SL/Form.pm index 62a76e710..8f6e616aa 100644 --- a/SL/Form.pm +++ b/SL/Form.pm @@ -565,26 +565,20 @@ 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; } sub parse_template { -- 2.20.1