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;
}
use Modern::Perl;
-use Test::More tests => 33;
+use Test::More tests => 34;
use Test::MockModule;
use t::lib::Mocks;
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
+};