PEAR is archived and read-only

This mirror preserves historical PEAR package releases and metadata so existing references remain available.

Home » Payment » Payment_DTA » Bug #3165

leading zero after comma in amount is ignored if more than 2 digits after comma

Details

Submitted2005-01-11 16:20 UTC
Frommc at spiess dot de
Assignedhstainer
StatusClosed
PackagePayment_DTA
PHP Version4.3.3
OSLinux ds80-237-204-40 2.6.8.1
Roadmaps(Not assigned)

Comments

[2005-01-11 16:20 UTC] mc at spiess dot de

Description:
------------
If in amount the first digit after the comma is zero, the the digit will be missed in the DTA.

e.g.:
Amount of EUR 1.05 will result in EUR 0.15 in the DTA.

error is presumably produced here:

DTA.php row 274
$parts = explode(".", $amount);

[2005-01-12 16:10 UTC] mc at spiess dot de

$amount= 1.023;
//begin: taken from DTA.php
if (substr_count($amount, ".") == 1) {
$parts = explode(".", $amount);

//$amount = $parts[0] . str_pad(round($parts[1] / ((strlen($parts[1])-2) * 10)), 2, "0", STR_PAD_RIGHT);

if (count($parts)>1) {
switch (strlen($parts[1])) {
case 1:
$amount = $parts[0] . $parts[1] . "0";
break;
case 2:
$amount = $parts[0] . $parts[1];
break;
default:
if (strlen($parts[1])>2) {
//$amount = $parts[0] . substr($parts[1], 0, 2);
$amount = $parts[0] . round($parts[1] / pow(10, strlen($parts[1])-2));
}
break;
}
} else {
$amount = $parts[0] . "00";
}
} else {
$amount = $amount * 100;
}
//end: taken from DTA.php
echo '<pre>' . $amount . '</pre>';

will be 0012 instead of 0123.

To avoid this effect, please make sure to round before using Payment_DTA.

round ($amount,2);

[2005-01-17 17:19 UTC] m dot hosse at geodigital dot org

This code is more difficult as it has to be.
Correct me if i am wrong, but IMO you can replace lines 273-298
--- SNIP ---
if (substr_count($amount, ".") == 1) {
$parts = explode(".", round($amount, 2));

//$amount = $parts[0] . str_pad(round($parts[1] / ((strlen($parts[1])-2) * 10)), 2, "0", STR_PAD_RIGHT);

if (count($parts)>1) {
switch (strlen($parts[1])) {
case 1:
$amount = $parts[0] . $parts[1] . "0";
break;
case 2:
$amount = $parts[0] . $parts[1];
break;
default:
if (strlen($parts[1])>2) {
//$amount = $parts[0] . substr($parts[1], 0, 2);
$amount = $parts[0] . round($parts[1] / pow(10, strlen($parts[1])-2));
}
break;
}
} else {
$amount = $parts[0] . "00";
}
} else {
$amount = $amount * 100;
}
--- SNAP ---

with just one line of code:

$amount = round($amount*100,0);

[2005-01-25 09:29 UTC] m dot hosse at geodigital dot org

If you use my solution you do not have to add more zeros because you already have the amount in cent.