Skip Menu |

This queue is for tickets about the Finance-Bank-NL-CLIEOP03 CPAN distribution.

Report information
The Basics
Id: 71836
Status: open
Priority: 0/
Queue: Finance-Bank-NL-CLIEOP03

People
Owner: pause-zebaz [...] nederhost.nl
Requestors: arjan [...] widlak.nl
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: 0.01
Fixed in: (no value)



Subject: Floating point error
There is a floating point error in the amount, that in rare cases takes a cent of the amount. The bug is in line 318 - 327 in this code $s .= sprintf ( "%04d%1s%04d%012d%010d%010d%9s\r\n", '0100', # Infocode 'A', # Variantcode ( $inc->{check} ? 1002 : 1001 ), # Transactiesoort int ( $inc->{amount} * 100 ), # Bedrag $inc->{account_number}, # Reknrbetaler $batch->{account}, # Reknrbegunstigde '' # Filler ); The %012d should be %012.0f, so that the floating point is taken with zero decimals. Because of the use of sprintf, there is no need for the int argument. Demonstration: wrong: perl -e 'printf "%012d", int("154.70" * 100)' right: perl -e 'printf "%012.0f", "154.70" * 100' A patch is attached to this message. $ patch -p0 CLIEOP03.pm < patch_CLIEOP3_floating_point_error.diff This is nice module by the way! Thanx Sebastiaan. Kind regards, Arjan Widlak.
Subject: patch_CLIEOP3_floating_point_error.diff
--- CLIEOP03.pm.orig 2011-10-21 15:33:19.314919555 +0200 +++ CLIEOP03.pm 2011-10-21 15:33:29.464934445 +0200 @@ -316,11 +316,11 @@ # Transactieinfo (0100) $s .= sprintf ( - "%04d%1s%04d%012d%010d%010d%9s\r\n", + "%04d%1s%04d%012.0f%010d%010d%9s\r\n", '0100', # Infocode 'A', # Variantcode ( $inc->{check} ? 1002 : 1001 ), # Transactiesoort - int ( $inc->{amount} * 100 ), # Bedrag + $inc->{amount} * 100, # Bedrag $inc->{account_number}, # Reknrbetaler $batch->{account}, # Reknrbegunstigde '' # Filler
Hi Arjan, The patch has been incorporated in version 0.02, to be published on CPAN later today. Kind regards, Sebastiaan
Subject: Re: [rt.cpan.org #71836] Floating point error
Date: Wed, 16 Nov 2011 11:16:48 +0100
To: bug-Finance-Bank-NL-CLIEOP03 [...] rt.cpan.org
From: arjan <arjan [...] unitedknowledge.nl>
Hi Sebastiaan, I never published a module on CPAN myself, so I don't know how that works, but when will the new version be publicly accessible? Kind regards, Arjan. On 10/24/2011 05:01 PM, Sebastiaan Hoogeveen via RT wrote: Show quoted text
> <URL: https://rt.cpan.org/Ticket/Display.html?id=71836> > > Hi Arjan, > > The patch has been incorporated in version 0.02, to be published on CPAN later today. > > Kind regards, > > Sebastiaan
Subject: Re: [rt.cpan.org #71836] Floating point error
Date: Wed, 16 Nov 2011 21:18:34 +0100
To: bug-Finance-Bank-NL-CLIEOP03 [...] rt.cpan.org
From: Sebastiaan Hoogeveen <s.hoogeveen [...] nederhost.nl>
Hi Arjan, Made an oops, has now been corrected. Had to bump the version to 0.03 to have the fix published now. Confirmed to be online at http://search.cpan.org/~zebaz/Finance-Bank-NL-CLIEOP03-0.03/ Probably next week 1.00 will be released supporting payment batches ('verzamelgiro') and incorporating a basic test suite. Sebastiaan On 16 nov. 2011, at 11:17, arjan@unitedknowledge.nl via RT wrote: Show quoted text
> Queue: Finance-Bank-NL-CLIEOP03 > Ticket <URL: https://rt.cpan.org/Ticket/Display.html?id=71836 > > > Hi Sebastiaan, > > I never published a module on CPAN myself, so I don't know how that > works, but when will the new version be publicly accessible? > > Kind regards, > Arjan. > > On 10/24/2011 05:01 PM, Sebastiaan Hoogeveen via RT wrote:
>> <URL: https://rt.cpan.org/Ticket/Display.html?id=71836> >> >> Hi Arjan, >> >> The patch has been incorporated in version 0.02, to be published on CPAN later today. >> >> Kind regards, >> >> Sebastiaan
> > >
RT-Send-CC: s.hoogeveen [...] nederhost.nl, arjan [...] unitedknowledge.nl
Hi Sebastiaan, First of all, thanks for this great module. I can also confirm that version 0.03 fixes the problem described by Arjan. I've found a related problem. The int() construct is still used in line 331 of CLIEOP03.pm (versie 0.03) $totalcents += int ( $inc->{amount} * 100 ); This also leads to a rounding error in some rare cases. For example the following perl snippet prints NOK! 6709 vs 6710! ################################ #!/usr/bin/env perl use strict; my $n = 67.10; my $a1 = int( $n * 100); my $a2 = sprintf "%.0f", $n * 100; if ($a1 == $a2) { print "OK.\n"; } else { print "NOK! $a1 vs $a2!\n"; } ################################ De problem can be fixed by replacing line 331 with: $totalcents += sprintf("%.0f", $inc->{amount} * 100); Best regards, Henry Tang