Closed internalsystemerror closed 3 years ago
You would have to convert the float to string before passing it to multiply
or divide
. Converting floats to string has the risk of inaccuracy which of the risk of the caller. Run the following in your terminal.
$a = '35';
$b = '-34.99';
echo ($a + $b);
Now suppose you call $money->multiply($a + $b)
. A float passed is not to be trusted. From version 4.0 we force callers to use int and string only, doing the conversion themselves.
I will leave this open for now because this not documented well enough in the CHANGELOG.
@frederikbosch It would be cool if you would show this in the documentation. https://www.moneyphp.org/en/stable/features/operation.html#multiplication-division
Now after coming back to a project float is not working
When using the
Money::multiply
andMoney::divide
methods, thanks to the changes in https://github.com/moneyphp/money/pull/648 we can pass an integer as well as a numeric string. It should also be possible to pass a float to these methods such as when calculating tax:$incTax = $money->multiply(1.2);
.If you agree then I can submit a PR to make the necessary adjustments.