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 <david@davidnind.com>
Signed-off-by: Victor Grousset/tuxayo <victor@tuxayo.net>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
(cherry picked from commit 56091d9660)
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
This commit is contained in:
Raphael Straub 2024-02-08 14:17:56 +00:00 committed by Lucas Gass
parent 0e62b0a697
commit a322d170ed
1 changed files with 2 additions and 6 deletions

View File

@ -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 {