From 27ef2dc95ddccefccf44ec03033a7e049f8db3eb Mon Sep 17 00:00:00 2001 From: Raphael Straub Date: Thu, 8 Feb 2024 14:17:56 +0000 Subject: [PATCH] Bug 36049: Fix price rounding This patch only fixes price rounding by using Math::BigFloat. To test: 0) Enable syspref OrderPriceRounding 1) Create an order line in acquisitions with vendor price 18.90 and a discount of 5 %. 2) Verify that the total (tax excl.) in the order table on the basket page is 17.95. 3) Apply the patch. 4) Reload the basket page. 5) Verify that the total (tax excl.) in the order table on the basket page now is 17.96, which is correct. 6) Run: prove t/Number/Price.t Sponsored-by: Karlsruhe Institute of Technology (KIT) Signed-off-by: David Nind --- Koha/Number/Price.pm | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/Koha/Number/Price.pm b/Koha/Number/Price.pm index e9a6aa748e..a0f847d495 100644 --- a/Koha/Number/Price.pm +++ b/Koha/Number/Price.pm @@ -19,6 +19,7 @@ package Koha::Number::Price; use Modern::Perl; +use Math::BigFloat; use Number::Format; use C4::Context; use Koha::Acquisition::Currencies; @@ -83,12 +84,7 @@ sub round { my $format_params = $self->_format_params; - # To avoid the system to crash, we will not format big number - # We divide per 100 because we want to keep the default DECIMAL_DIGITS (2) - # error - round() overflow. Try smaller precision or use Math::BigFloat - return $self->value if $self->value > Number::Format::MAX_INT/100; - - return Number::Format->new(%$format_params)->round($self->value); + return Number::Format->new(%$format_params)->round( Math::BigFloat->new( $self->value ) )->bdstr(); } sub _format_params { -- 2.44.0