Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 1.4.3

Bug #3165 leading zero after comma in amount is ignored if more than 2 digits after comma
Submitted: 2005-01-11 16:20 UTC
From: mc at spiess dot de Assigned: hstainer
Status: Closed Package: Payment_DTA
PHP Version: 4.3.3 OS: Linux ds80-237-204-40 2.6.8.1
Roadmaps: (Not assigned)    
Subscription  


 [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);

Comments

 [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-16 22:44 UTC] hstainer
Thank you for your bug report. This issue has been fixed in the latest released version of the package, which you can download at http://pear.php.net/get/Payment_DTA Fixed in release 1.1.0. Thanks for submitting this bug.
 [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-17 19:37 UTC] hstainer
Hm, your solution should work if a str_pad command is added. I'll improve this part in the next release!
 [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.