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

(-)a/C4/Koha.pm (+34 lines)
Lines 1310-1315 sub IsKohaFieldLinked { Link Here
1310
    return $is_linked->[0];
1310
    return $is_linked->[0];
1311
}
1311
}
1312
1312
1313
=head2 compareNumbers
1314
1315
    As floating point numbers may be rounded differently and
1316
    inconsistently, this function converts them to strings of
1317
    a given accuracy for the comparison.
1318
1319
    my $number1 = 5.60000;
1320
    my $number2 = 5.6;
1321
    if (C4::Koha::compareNumbers($number1,$number2,2) {
1322
        print "The two numbers match.\n";
1323
    } else {
1324
        print "The two numbers do not match.\n";
1325
    }
1326
1327
    Return 1 if the numbers match.
1328
1329
=cut
1330
1331
sub compareNumbers {
1332
    my ($n1,$n2,$accuracy) = @_;
1333
    if (defined $n1  && defined $n2) {
1334
        if (!defined $accuracy) {
1335
            $accuracy = 2;
1336
        }
1337
        my $format1 = "%.${accuracy}f";
1338
        my $format2 = $format1;
1339
        return (sprintf($format1,$n1) eq sprintf($format2,$n2));
1340
    } elsif (!defined $n1 && !defined $n2) {
1341
        return 1;
1342
    } else {
1343
        return 0;
1344
    }
1345
}
1346
1313
1;
1347
1;
1314
1348
1315
__END__
1349
__END__
(-)a/C4/Overdues.pm (-1 / +1 lines)
Lines 576-582 sub UpdateFine { Link Here
576
        # we're updating an existing fine.  Only modify if amount changed
576
        # we're updating an existing fine.  Only modify if amount changed
577
        # Note that in the current implementation, you cannot pay against an accruing fine
577
        # Note that in the current implementation, you cannot pay against an accruing fine
578
        # (i.e. , of accounttype 'FU').  Doing so will break accrual.
578
        # (i.e. , of accounttype 'FU').  Doing so will break accrual.
579
        if ( $data->{'amount'} ne sprintf('%.6f', $amount) ) {
579
        if ( C4::Koha::compareNumbers($data->{'amount'},$amount,6) ) {
580
            my $accountline = Koha::Account::Lines->find( $data->{accountlines_id} );
580
            my $accountline = Koha::Account::Lines->find( $data->{accountlines_id} );
581
            my $diff = $amount - $data->{'amount'};
581
            my $diff = $amount - $data->{'amount'};
582
582
(-)a/t/Koha.t (-2 / +13 lines)
Lines 25-31 use Module::Load::Conditional qw/check_install/; Link Here
25
25
26
BEGIN {
26
BEGIN {
27
    if ( check_install( module => 'Test::DBIx::Class' ) ) {
27
    if ( check_install( module => 'Test::DBIx::Class' ) ) {
28
        plan tests => 38;
28
        plan tests => 47;
29
    } else {
29
    } else {
30
        plan skip_all => "Need Test::DBIx::Class"
30
        plan skip_all => "Need Test::DBIx::Class"
31
    }
31
    }
Lines 155-158 ok($@ eq '', 'NormalizeISSN does not throw exception when parsing invalid ISSN') Link Here
155
is($issns[0], 'abc', 'Original ISSN passed through even if invalid');
155
is($issns[0], 'abc', 'Original ISSN passed through even if invalid');
156
is(scalar(@issns), 1, 'zero additional variations returned of invalid ISSN');
156
is(scalar(@issns), 1, 'zero additional variations returned of invalid ISSN');
157
157
158
ok( C4::Koha::compareNumbers(1,1,2),'1  matches 1 as expected');
159
ok( C4::Koha::compareNumbers(1.25,1.251,2),'1.25 matches 1.251 with 2 decimal accuracy');
160
161
ok(!C4::Koha::compareNumbers(1,2,2),'1 does not match 2 as expected');
162
ok(!C4::Koha::compareNumbers(undef,1    ,2),'undef does not match 1 as expected');
163
ok(!C4::Koha::compareNumbers(1,undef,2),'1 does not match undef as expected');
164
165
ok(C4::Koha::compareNumbers( 5.600000 , 5.6 ),'number-number test');
166
ok(C4::Koha::compareNumbers( 5.600000 ,'5.6'),'number-string test');
167
ok(C4::Koha::compareNumbers('5.600000', 5.6 ),'string-number test');
168
ok(C4::Koha::compareNumbers('5.600000','5.6'),'string-string test');
169
158
1;
170
1;
159
- 

Return to bug 17138