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

stppbilling setAmount bug #1

Closed
coedycode opened this issue Feb 2, 2017 · 3 comments
Closed

stppbilling setAmount bug #1

coedycode opened this issue Feb 2, 2017 · 3 comments

Comments

@coedycode
Copy link

There's a strange rounding issue with php floats cast to integers.

The line:
$this->options["amount"]["value"] = (integer) ($amount * 100);

If the amount provided = 10.04, the final value becomes 1003

floor(10.04 * 100) also gives 1003

number_format((10.04 * 100), 0, '.', '') seems to be the only reliable solution.

@Westie
Copy link
Owner

Westie commented Feb 2, 2017

Yes, PHP can be god awful when it comes to its representing floats and that sort of thing.

I'm allergic to number_format however (it just seems too unwieldy) so I'll change it to use sprintf.

14:13 <&Westie> @@ echo sprintf("%.0f", 10.04 * 100);
14:13 < Happycat> 1004

Thank you for pointing that out!

@coedycode
Copy link
Author

coedycode commented Feb 2, 2017 via email

@Westie
Copy link
Owner

Westie commented Feb 2, 2017

I should really look at the docs again for updates, I haven't looked at this since I was forced to create it as there wasn't any other solution out there for STPP.

I've always found Secure Trading's way of doing this (the Java proxy method) interesting, to say at the least!

@Westie Westie closed this as completed Feb 2, 2017
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

2 participants