digitick / php-sepa-xml

* THIS PROJECT IS NO LONGER MAINTAINED* SEPA file generator in PHP
107 stars 63 forks source link

computers suck at math #50

Open foxdie opened 10 years ago

foxdie commented 10 years ago

hi,

You may have rounding errors in the constructor of BaseTransferInformation :

$amount = (integer) ($amount * 100); //may cause rounding errors

should be replaced with:

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

see why computers suck at math : http://www.techradar.com/news/computing/why-computers-suck-at-maths-644771/1

thanks for your work :)

ghost commented 8 years ago

Casting to integer will result into cut of the number and not into a rounded numbers. That because you are right.

Normally by casting to integer: 100,5 would result into 100. 100,4 would result into 100.

nicolasbadia commented 7 years ago

I'm have rounding issues too. If I set the amount to 9.78, the output will display 9.77. The proposed solution worked for me.

BenjaminPaap commented 7 years ago

Use https://github.com/php-sepa-xml/php-sepa-xml instead. As far as I know we fixed all rounding issues there. It's a fork of this repository which is actively maintained.

nicolasbadia commented 7 years ago

Thanks. I will use this fork now. Also find out that this is fixed in master by https://github.com/digitick/php-sepa-xml/commit/6c68d02ce575428145ee389150cd3a6f4b9bcba1 and that this issue is a duplicate of https://github.com/digitick/php-sepa-xml/issues/28