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

GmpCalculator multiply: gmp_init() error when fractional part with leading 0 #286

Closed
Michael-vb opened this issue Oct 5, 2016 · 5 comments

Comments

@Michael-vb
Copy link

$phpCalculator = new \Money\Calculator\PhpCalculator;
$gmpCalculator = new \Money\Calculator\GmpCalculator;
$bcCalculator = new \Money\Calculator\BcMathCalculator;
echo $phpCalculator->multiply('100', 0.029) . "\n"; // 2.9
echo $gmpCalculator->multiply('100', 0.029) . "\n"; // .0 gmp_init(): Unable to convert variable to GMP - string is not an integer
echo $bcCalculator->multiply('100', 0.029) . "\n"; // 2.900
@sagikazarmark
Copy link
Collaborator

I think a similar issue has already be raised here: #278

Just for curiousity: what made you using the calculator directly? As far as I know it works well with the money object.

@frederikbosch since this issue keeps coming back, maybe we should do something about it. Put some lines in the docs, even throw an exception somewhere?

@Michael-vb
Copy link
Author

@sagikazarmark no it didn't work with the money object too. But by default money object uses bcmath and this error occurs when bcmath is not installed. e.g.:

Money::registerCalculator(\Money\Calculator\GmpCalculator::class);
(new Money(1000, new Currency('USD')))->multiply(0.029);

will throw the error

@frederikbosch
Copy link
Member

@Michael-vb This has been fixed in the latest master.

@frederikbosch
Copy link
Member

Thanks for reporting.

@Michael-vb
Copy link
Author

@frederikbosch thank you! I've seen. Just answered the previous question

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