View | Details | Raw Unified | Return to bug 26239
Collapse All | Expand All

(-)a/Koha/Number/Price.pm (-2 / +1 lines)
Lines 40-50 sub format { Link Here
40
    return unless defined $self->value;
40
    return unless defined $self->value;
41
41
42
    my $format_params = $self->_format_params( $params );
42
    my $format_params = $self->_format_params( $params );
43
44
    # To avoid the system to crash, we will not format big number
43
    # To avoid the system to crash, we will not format big number
45
    # We divide per 100 because we want to keep the default DECIMAL_DIGITS (2)
44
    # We divide per 100 because we want to keep the default DECIMAL_DIGITS (2)
46
    # error - round() overflow. Try smaller precision or use Math::BigFloat
45
    # error - round() overflow. Try smaller precision or use Math::BigFloat
47
    return $self->value if $self->value > Number::Format::MAX_INT/100;
46
    return $self->value if abs($self->value) > Number::Format::MAX_INT/100;
48
47
49
    return Number::Format->new(%$format_params)->format_price($self->value);
48
    return Number::Format->new(%$format_params)->format_price($self->value);
50
}
49
}
(-)a/t/Number/Price.t (-2 / +2 lines)
Lines 1-6 Link Here
1
use Modern::Perl;
1
use Modern::Perl;
2
2
3
use Test::More tests => 34;
3
use Test::More tests => 35;
4
4
5
use Test::MockModule;
5
use Test::MockModule;
6
use t::lib::Mocks;
6
use t::lib::Mocks;
Lines 37-42 is( Koha::Number::Price->new(1234567890)->format( $format ), Link Here
37
    '1,234,567,890.00', 'US: format 1234567890' );
37
    '1,234,567,890.00', 'US: format 1234567890' );
38
38
39
is( Koha::Number::Price->new(100000000000000)->format, '100000000000000', 'Numbers too big are not formatted');
39
is( Koha::Number::Price->new(100000000000000)->format, '100000000000000', 'Numbers too big are not formatted');
40
is( Koha::Number::Price->new(-100000000000000)->format, '-100000000000000', 'Negative numbers too big are not formatted');
40
41
41
is( Koha::Number::Price->new->format( { %$format, with_symbol => 1 } ),
42
is( Koha::Number::Price->new->format( { %$format, with_symbol => 1 } ),
42
    '$0.00', 'US: format 0 with symbol' );
43
    '$0.00', 'US: format 0 with symbol' );
43
- 

Return to bug 26239