Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rounding not correct #2

Closed
elrafman opened this issue Mar 7, 2012 · 2 comments
Closed

Rounding not correct #2

elrafman opened this issue Mar 7, 2012 · 2 comments
Assignees

Comments

@elrafman
Copy link
Contributor

elrafman commented Mar 7, 2012

Hi
when sending the order amount to the saferpay the amount is sometimes not rounded correctly

the calculation
intval(Mage::helper('saferpay_be')->round($amount, 2) * 100)
should be replaced by
intval(round(Mage::helper('saferpay_be')->round($amount, 2) * 100))
as you may have problems using intval with floating point numbers.

Cheers

Rafael

@tim-bezhashvyly
Copy link
Contributor

Hi Rafael.

Can you please tell under which conditions you got wrong rounding so I can check it?

Thanks,
Tim.

@danielgratzl
Copy link

It's line 285 in app/code/community/Saferpay/Ecommerce/Model/Abstract.php of your current implementation

 'AMOUNT'                => intval($helper->round($this->getOrder()->getGrandTotal(), 2) * 100)

as elrafman suggests you should change this to

 'AMOUNT'                => intval(round($helper->round($this->getOrder()->getGrandTotal(), 2) * 100))

All this hassle is caused by this http://en.wikipedia.org/wiki/Floating_point#Accuracy_problems

Use 23.80 as a testcase.. With your current version it calculates to 2379 which is obviously incorrect

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants