Closed raimon-segura closed 10 years ago
Hi,
I have been checking the code for "Payment Info total Amount" and I see a little issue: https://github.com/dmitrirussu/php-sepa-xml-generator/blob/master/lib/SEPA/PaymentInfo.php#L440
You made the sum with float variables, best practices said that it must be done with bcadd , that supports fixed point operations.
Another thing is the conversion from float to string, https://github.com/dmitrirussu/php-sepa-xml-generator/blob/master/lib/SEPA/ValidationRules.php#L81
We use http://es1.php.net/number_format function, I think it's equivalent, but I don't know for sure.
To resume, we sum money like this:
// constants $SCALE = 2; $ROUND_SCALE = 2;
// returns formated string $amount_1 = number_format( $float_1, $ROUND_SCALE, '.', ''); $amount_2 = number_format( $float_2, $ROUND_SCALE, '.', '');
// returns string $unformated_sum = bcadd( $amount1, $amount2, $SCALE); // returns float $unformated_rounded_sum = round( $unformated_sum , $ROUND_SCALE); // returns string $sum = number_format( $float_2, $ROUND_SCALE, '.', '');
based on: http://css.dzone.com/books/practical-php-patterns/basic/practical-php-patterns-money
Thanks!
Thanks Raimon, I have fixed this problem, I added a new method in validation rules which do sum of Operands with bcadd,
Hi,
I have been checking the code for "Payment Info total Amount" and I see a little issue: https://github.com/dmitrirussu/php-sepa-xml-generator/blob/master/lib/SEPA/PaymentInfo.php#L440
You made the sum with float variables, best practices said that it must be done with bcadd , that supports fixed point operations.
Another thing is the conversion from float to string, https://github.com/dmitrirussu/php-sepa-xml-generator/blob/master/lib/SEPA/ValidationRules.php#L81
We use http://es1.php.net/number_format function, I think it's equivalent, but I don't know for sure.
To resume, we sum money like this:
// constants $SCALE = 2; $ROUND_SCALE = 2;
// returns formated string $amount_1 = number_format( $float_1, $ROUND_SCALE, '.', ''); $amount_2 = number_format( $float_2, $ROUND_SCALE, '.', '');
// returns string $unformated_sum = bcadd( $amount1, $amount2, $SCALE); // returns float $unformated_rounded_sum = round( $unformated_sum , $ROUND_SCALE); // returns string $sum = number_format( $float_2, $ROUND_SCALE, '.', '');
based on: http://css.dzone.com/books/practical-php-patterns/basic/practical-php-patterns-money
Thanks!