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