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

(-)a/Koha/Number/Price.pm (-6 / +2 lines)
Lines 19-24 package Koha::Number::Price; Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Math::BigFloat;
22
use Number::Format;
23
use Number::Format;
23
use C4::Context;
24
use C4::Context;
24
use Koha::Acquisition::Currencies;
25
use Koha::Acquisition::Currencies;
Lines 83-94 sub round { Link Here
83
84
84
    my $format_params = $self->_format_params;
85
    my $format_params = $self->_format_params;
85
86
86
    # To avoid the system to crash, we will not format big number
87
    return Number::Format->new(%$format_params)->round( Math::BigFloat->new( $self->value ) )->bdstr();
87
    # We divide per 100 because we want to keep the default DECIMAL_DIGITS (2)
88
    # error - round() overflow. Try smaller precision or use Math::BigFloat
89
    return $self->value if $self->value > Number::Format::MAX_INT/100;
90
91
    return Number::Format->new(%$format_params)->round($self->value);
92
}
88
}
93
89
94
sub _format_params {
90
sub _format_params {
(-)a/t/Number/Price.t (-2 / +4 lines)
Lines 1-6 Link Here
1
use Modern::Perl;
1
use Modern::Perl;
2
2
3
use Test::More tests => 35;
3
use Test::More tests => 36;
4
4
5
use Test::MockModule;
5
use Test::MockModule;
6
use t::lib::Mocks;
6
use t::lib::Mocks;
Lines 136-141 is( Koha::Number::Price->new(3)->unformat, '3', 'CHF: unformat 3' ); Link Here
136
is( Koha::Number::Price->new(1234567890)->unformat,
136
is( Koha::Number::Price->new(1234567890)->unformat,
137
    '1234567890', 'CHF: unformat 1234567890' );
137
    '1234567890', 'CHF: unformat 1234567890' );
138
138
139
# Rounding
140
is( Koha::Number::Price->new(17.955)->round, '17.96', 'Round 17.955' );
141
139
subtest 'Changes for format' => sub { # See also bug 18736
142
subtest 'Changes for format' => sub { # See also bug 18736
140
    plan tests => 3;
143
    plan tests => 3;
141
144
142
- 

Return to bug 36049