diff --git a/Koha/Number/Price.pm b/Koha/Number/Price.pm index 7b0b826a14..e9a6aa748e 100644 --- a/Koha/Number/Price.pm +++ b/Koha/Number/Price.pm @@ -40,11 +40,10 @@ sub format { return unless defined $self->value; my $format_params = $self->_format_params( $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 $self->value if abs($self->value) > Number::Format::MAX_INT/100; return Number::Format->new(%$format_params)->format_price($self->value); } diff --git a/t/Number/Price.t b/t/Number/Price.t index 141f00ffa2..ce607a83a1 100644 --- a/t/Number/Price.t +++ b/t/Number/Price.t @@ -1,6 +1,6 @@ use Modern::Perl; -use Test::More tests => 34; +use Test::More tests => 35; use Test::MockModule; use t::lib::Mocks; @@ -37,6 +37,7 @@ is( Koha::Number::Price->new(1234567890)->format( $format ), '1,234,567,890.00', 'US: format 1234567890' ); is( Koha::Number::Price->new(100000000000000)->format, '100000000000000', 'Numbers too big are not formatted'); +is( Koha::Number::Price->new(-100000000000000)->format, '-100000000000000', 'Negative numbers too big are not formatted'); is( Koha::Number::Price->new->format( { %$format, with_symbol => 1 } ), '$0.00', 'US: format 0 with symbol' );