@@ -, +, @@ test --- C4/Acquisition.pm | 2 +- t/Number/Price.t | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) --- a/C4/Acquisition.pm +++ a/C4/Acquisition.pm @@ -2023,7 +2023,7 @@ sub get_rounding_sql { my ( $round_string ) = @_; my $rounding_pref = C4::Context->preference('OrderPriceRounding') // q{}; if ( $rounding_pref eq "nearest_cent" ) { - return "CAST($round_string*100 AS UNSIGNED)/100"; + return "CAST($round_string*100 AS SIGNED)/100"; } return $round_string; } --- a/t/Number/Price.t +++ a/t/Number/Price.t @@ -1,6 +1,6 @@ use Modern::Perl; -use Test::More tests => 33; +use Test::More tests => 34; use Test::MockModule; use t::lib::Mocks; @@ -134,3 +134,17 @@ is( Koha::Number::Price->new->unformat, '0', 'CHF: unformat 0' ); is( Koha::Number::Price->new(3)->unformat, '3', 'CHF: unformat 3' ); is( Koha::Number::Price->new(1234567890)->unformat, '1234567890', 'CHF: unformat 1234567890' ); + +subtest 'Changes for format' => sub { # See also bug 18736 + plan tests => 3; + + t::lib::Mocks::mock_preference( 'CurrencyFormat', 'US' ); + + is( Koha::Number::Price->new(-2.125)->format, "-2.13", "Check negative value" ); + my $large_number = 2**53; # MAX_INT + my $price = Koha::Number::Price->new($large_number); + is( $price->format, $price->value, 'Format '.$price->value.' returns value' ); + like( Koha::Number::Price->new( 2**53/100 )->format, + qr/\d\.\d{2}$/, 'This price still seems to be formatted' ); + # Note that the comparison with MAX_INT is already subject to rounding +}; --